capture clear
capture log close
capture program drop _all
capture macro drop _all
drop _all
graph drop _all
set more off
set matsize 800
graph set window fontface "Times New Roman"

capture mkdir figures
capture mkdir tables


/*** Set Directory Structure ***/


gl ui "/Users/kmitm/Dropbox/Missouri_UI/ReplicationKitFinal/"
gl statedata "${ui}"
gl figures "${ui}figures/"
gl tables "${ui}tables/"
gl sep "/"


/*******************************************************************************
* Stata 17.0
*  PROJECT:    Micro and Macro Effects of UI Policies: Evidence from Missouri
*  PROGRAMMER: Brendan Moore
*  PROGRAM:    output.do
*
*  UPDATED:	   01/07/25
*******************************************************************************/

// set globals
global startyr_reg = 2010
global startqtr_reg = 1
global endyr_reg = 2012
global endqtr_reg = 3
global begyq = yq($startyr_reg, $startqtr_reg)
global endyq = yq($endyr_reg, $endqtr_reg)



/******************************************************************************/
*		Table 1: Effects on Unemployment Rate & UI Duration
/******************************************************************************/
cap drop prog do_table1
prog define do_table1

// read in file with max state UI durations by daily basis, collapse it to quarterly
use "${statedata}FullFinal_AllYears-Daily.dta", clear
	
	gen quarter = 1 if inrange(month,1,3)	// construct quarterly variable
	replace quarter = 2 if inrange(month,4,6)
	replace quarter = 3 if inrange(month,7,9)
	replace quarter = 4 if inrange(month,10,12)
	collapse (mean) totalweeks_daily, by(statefips year quarter)
	label var totalweeks_daily "State's Maximum WBA averaged over quarter"
	ren totalweeks_daily meanwks
	ren statefips fipsstate 		// rename variable to make it match to other
	save "${statedata}UI_maxduration_state_collapsed.dta", replace

	// loop it over two endings
	// read in file where we seasonally adjust spearately (doesn't matter for this)
	use	"${statedata}synth_ready_quarterly.dta", clear

	// merge on UI max weeks UI data
	rename qtr quarter
	merge m:1 year quarter fipsstate using "${statedata}UI_maxduration_state_collapsed.dta"
	keep if _merge==3
	drop _merge
	rename quarter qtr
	// identify the value of state = Missouri
	egen idd = group(state)

	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
	"HAWAII", "MASSACHUSETTS","DISTRICT OF COLUMBIA")	
	
	
	// Merge UI trust fund data	
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.
	
	replace ui_debt=0 if ui_debt==.
	drop _merge
	
	// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
	gen bench_ctr = (peak_near_MO==1 & ui_debt>0)
	
	keep if inrange(yrqtr,${begyq},yq(2013,4))
	xtset fipsstate yrqtr	// set as a time series	
	
	// log mean weeks duration benefit
	gen log_meanwks = log(meanwks)

	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0


	eststo clear
	
	*endtimes
	local eyears 2012 2013 
	local equart 3 4 

	local timecount: word count(`eyears')

	forval k=1/`timecount'{
		local theendqtr: word `k' of `equart'
		local theendyr: word `k' of `eyears'
		
	*****   reg Y on MO x Post, one way FE; cluster at the state level
	reghdfe urate MO_post if yrqtr<=yq(`theendyr',`theendqtr') & bench_ctr==1, a(yrqtr fipsstate) vce(cluster fipsstate)
		// put estimates/parameters in locals
			local b_urate_`theendyr'Q`theendqtr' = _b[MO_post]	// store beta coefficient
			local onewaySE_urate_`theendyr'Q`theendqtr' = _se[MO_post]	// store standard error
			local N_urate_`theendyr'Q`theendqtr' = e(N)		// store number of obs
			
		// format both the beta and SE
		local b_urate_`theendyr'Q`theendqtr' : di %4.3f `b_urate_`theendyr'Q`theendqtr''
		local onewaySE_urate_`theendyr'Q`theendqtr' : di %4.3f `onewaySE_urate_`theendyr'Q`theendqtr''
		local N_urate_`theendyr'Q`theendqtr' : di %5.0fc `N_urate_`theendyr'Q`theendqtr''

	*****  reg Y on MO x Post, two way FE; cluster at the state & year-quarter level
	reghdfe urate MO_post if yrqtr<=yq(`theendyr',`theendqtr')  & bench_ctr==1, a(yrqtr fipsstate) vce(cluster yrqtr fipsstate)
		// put estimates/parameters in locals
		local twowaySE_urate_`theendyr'Q`theendqtr' = _se[MO_post]	// store standard error
		local twowaySE_urate_`theendyr'Q`theendqtr' : di %4.3f `twowaySE_urate_`theendyr'Q`theendqtr''
	}
	
		*****   reg Y on MO x Post, one way FE; cluster at the state level
	reghdfe log_meanwks MO_post if yrqtr<=yq(2012,3)  & bench_ctr==1, a(yrqtr fipsstate) vce(cluster fipsstate)
		// put estimates/parameters in locals
		local b_logwks_2012Q3 = _b[MO_post]	// store beta coefficient
		local onewaySE_logwks_2012Q3 = _se[MO_post]	// store standard error
		local N_logwks_2012Q3 = e(N)		// store number of obs
		// format both the beta and SE
		local b_logwks_2012Q3 : di %4.3f `b_logwks_2012Q3'
		local onewaySE_logwks_2012Q3 : di %4.3f `onewaySE_logwks_2012Q3'
		local N_logwks_2012Q3 : di %5.0fc `N_logwks_2012Q3'		
	reghdfe log_meanwks MO_post if yrqtr<=yq(2012,3)  & bench_ctr==1, a(yrqtr fipsstate) vce(cluster yrqtr fipsstate)
		// put estimates/parameters in locals
		local twowaySE_logwks_2012Q3 = _se[MO_post]	// store standard error
		local twowaySE_logwks_2012Q3 : di %4.3f `twowaySE_logwks_2012Q3'
			
texdoc init "${tables}regressions_urate_bench.tex", replace force
tex \begin{tabular}{lccc} \toprule \toprule
tex     & Log(Max Weeks UI) & \multicolumn{2}{l}{Unemployment Rate} \\ 
tex      &  (1) & (2) & (3) \\ \midrule 
tex    \addlinespace
tex    \addlinespace
tex     $\hat{\beta}_{MO\_post}$  & `b_logwks_2012Q3'& `b_urate_2012Q3' & `b_urate_2013Q4' \\
tex     One-way clustered SE  & (`onewaySE_logwks_2012Q3') & (`onewaySE_urate_2012Q3') & (`onewaySE_urate_2013Q4') \\
tex     Two-way clustered SE  & (`twowaySE_logwks_2012Q3') & (`twowaySE_urate_2012Q3') & (`twowaySE_urate_2013Q4')\\
tex    \addlinespace
tex    \multicolumn{1}{l}{Start Period} & 2010Q1 & 2010Q1 & 2010Q1 \\
tex    \multicolumn{1}{l}{End Period} & 2012Q3 &  2012Q3 & 2013Q4\\
tex \midrule
tex \$N\$ & `N_logwks_2012Q3' & `N_urate_2012Q3' & `N_urate_2013Q4' \\ \bottomrule \bottomrule
tex \end{tabular}
texdoc close		

		
end 


/******************************************************************************/
*		Table 2 & 3 : Estimated Effect of UI Cut and Decomposition
/******************************************************************************/
cap drop prog do_tables2and3
prog define do_tables2and3

*******
*******
// IMPORTANT NOTE: To make the coding easier to adjust all = bench, i.e. restricted set of states == 1
//					thus, for compgroup=="restrict" is actually for all control units 
*******
*******

*seasonal adjustment
local satype rat rat sep sep 
* what type of comparison group
local compgroup restrict all restrict all

local timecount: word count(`compgroup')

forval k=1/`timecount' {
	local sa_method: word `k' of `satype'
	local comp_type: word `k' of `compgroup'

// read in diff file type depending on SA method
if "`sa_method'"=="sep" {
	local sa_longform "separate"
	use	"${statedata}synth_ready_quarterly.dta", clear
}
if "`sa_method'"=="rat" {
	local sa_longform "ratio"
	use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear
}
// drop states that also changed UI policies during this time or for which there isn't sufficient data
drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
	"MASSACHUSETTS","HAWAII","DISTRICT OF COLUMBIA")

keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	
// merge "peak unemployment rate" info
merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
	// Merge UI trust fund data	
merge m:1 state using "${statedata}ui_trust_fund.dta"

drop if _merge==2 // drops U.S. V.I.

replace ui_debt=0 if ui_debt==.
drop _merge


	// get the pre-treatment mean for Missouri
	egen idd = group(state)
	qui summ idd
	// put the min and max of state numbers into locals (necessary for permutation test)
	local statemin = `r(min)'
	local statemax = `r(max)'
	// "leave out" Missouri
	qui summ idd if state=="MISSOURI"
	local mizzou = `r(mean)'	// store the value of Missouri in this local	

// whether or not to "take out" non-near peak unemployment MO states
if "`comp_type'"=="all" {
	keep if peak_near_MO==1 & ui_debt>0
}
xtset idd yrqtr	// set as a time series			
	
********************	
*****   newV/U
********************
***		reg on MO x Post, two way FE; cluster at the state level
	reghdfe log_newv_over_unemp MO_post, a(yrqtr idd) vce(cluster idd)
		local b_VU_`sa_method'_`comp_type' = _b[MO_post]	// store beta coefficient
		local oneway_VU_`sa_method'_`comp_type' = _se[MO_post]	// store standard error
		local N_`sa_method'_`comp_type' = e(N)
		di `b_VU_`sa_method'_`comp_type''
		// format both the beta and SE
		local b_VU_`sa_method'_`comp_type' : di %4.3f `b_VU_`sa_method'_`comp_type''
		local oneway_VU_`sa_method'_`comp_type' : di %4.3f `oneway_VU_`sa_method'_`comp_type''
		local N_`sa_method'_`comp_type' : di %5.0fc `N_`sa_method'_`comp_type''			
			
	*****  reg newV/U on MO x Post, two way FE; cluster at the state & year-quarter level
	reghdfe log_newv_over_unemp MO_post, a(yrqtr idd) vce(cluster yrqtr idd)
		local twoway_VU_`sa_method'_`comp_type' = _se[MO_post]	// store standard error
		// format the SE
		local twoway_VU_`sa_method'_`comp_type' : di %4.3f `twoway_VU_`sa_method'_`comp_type''
		
********************	
*****   stable H/ new V
********************
***		reg on MO x Post, two way FE; cluster at the state level
	reghdfe log_newsh_over_newv MO_post, a(yrqtr idd) vce(cluster idd)
		local b_HV_`sa_method'_`comp_type' = _b[MO_post]	// store beta coefficient
		local oneway_HV_`sa_method'_`comp_type' = _se[MO_post]	// store standard error
		// format both the beta and SE
		local b_HV_`sa_method'_`comp_type' : di %4.3f `b_HV_`sa_method'_`comp_type''
		local oneway_HV_`sa_method'_`comp_type' : di %4.3f `oneway_HV_`sa_method'_`comp_type''
			
	*****  reg newV/U on MO x Post, two way FE; cluster at the state & year-quarter level
	reghdfe log_newsh_over_newv MO_post, a(yrqtr idd) vce(cluster yrqtr idd)
		local twoway_HV_`sa_method'_`comp_type' = _se[MO_post]	// store standard error
		// format the SE
		local twoway_HV_`sa_method'_`comp_type' : di %4.3f `twoway_HV_`sa_method'_`comp_type''

****************************************************
**	Calculate Effect on Job Finding Rate, Steady-State Unemployment

	*Step 1: Obtain UE and EU flows that are adjusted for time aggregation bias
		use "${statedata}f_rate_state_cps_sa_shimeradj.dta", clear
		// only keep Missouri observations during relevant time span
			keep if statenameupper=="MISSOURI" & inrange(ym,ym(2011,1),ym(2011,3))
			tsset ym 	// set as time series(
		// extract the mean JFR in the quarter we want
			summ job_finding_rate
			local jfr_mean = `r(mean)'
			
		// same thing but for separation rate (Shimer adj EU rate)
		use "${statedata}s_rate_state_cps_sa_shimeradj.dta", clear
			// only keep Missouri observations during relevant time span
			keep if statenameupper=="MISSOURI" & inrange(ym,ym(2011,1),ym(2011,3))

			tsset ym 	// set as time series
		// extract the mean separation rate in the quarter we want
			summ separation_rate
			local sep_mean = `r(mean)'
			
		// create observed steady state unemployment rate
			local normal_ss_urate = 100*`sep_mean'/(`sep_mean'+ `jfr_mean')	
			// local for micro effect:
			local micro_`sa_method'_`comp_type' = `b_VU_`sa_method'_`comp_type'' + (1/(1-0.55))*`b_HV_`sa_method'_`comp_type''
			
			// local for theta (increase in market tightness):
			local theta_`sa_method'_`comp_type' = `b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type''
				
			// calclate job finding rate:
			local jfrate_`sa_method'_`comp_type' = `micro_`sa_method'_`comp_type'' + (0.55*(`theta_`sa_method'_`comp_type''))

			// calculate how much JFR Δ & new URate as result of policy:
			local ctrf_jfr_`sa_method'_`comp_type' = `jfr_mean'*exp((-1)*`jfrate_`sa_method'_`comp_type'')
			local ctrf_ss_urate_`sa_method'_`comp_type' = 100*`sep_mean'/(`sep_mean'+ `ctrf_jfr_`sa_method'_`comp_type'')
			// lastly, calculate the difference between the normal and ctrf URates (or JFR)
			local ss_urate_diff_`sa_method'_`comp_type' = `normal_ss_urate' - `ctrf_ss_urate_`sa_method'_`comp_type''			

			// format numbers	
			local jfrate_`sa_method'_`comp_type': di %4.3f `jfrate_`sa_method'_`comp_type''
			local ss_urate_diff_`sa_method'_`comp_type': di %3.2f `ss_urate_diff_`sa_method'_`comp_type''			
	}		


*** Write .tex table for main effects (all New Hires & New Vacancies)
texdoc init "${tables}panel_regressions_beta_bench.tex", replace force
tex \begin{tabular}{lrcccc} \toprule \toprule
tex     & &  (1) & (2) & (3) & (4) \\ \midrule 
tex    \multicolumn{2}{l}{A. \$Vacancies / Unemployment\$} & & & & \\
tex    & $\hat{\beta}_{MO\_post}$ & `b_VU_rat_all' & `b_VU_rat_restrict' & `b_VU_sep_all' & `b_VU_sep_restrict' \\
tex    & One-way clustered SE & (`oneway_VU_rat_all') & (`oneway_VU_rat_restrict') & (`oneway_VU_sep_all') & (`oneway_VU_sep_restrict')  \\
tex    & Two-way clustered SE & (`twoway_VU_rat_all') & (`twoway_VU_rat_restrict') & (`twoway_VU_sep_all') & (`twoway_VU_sep_restrict')  \\
tex    \addlinespace
tex    \multicolumn{2}{l}{B. \$Hires / Vacancies\$} & & & & \\
tex    & $\hat{\beta}_{MO\_post}$ & `b_HV_rat_all' & `b_HV_rat_restrict' & `b_HV_sep_all' & `b_HV_sep_restrict' \\
tex    & One-way clustered SE & (`oneway_HV_rat_all') & (`oneway_HV_rat_restrict') & (`oneway_HV_sep_all') & (`oneway_HV_sep_restrict') \\
tex    & Two-way clustered SE & (`twoway_HV_rat_all') & (`twoway_HV_rat_restrict') & (`twoway_HV_sep_all') & (`twoway_HV_sep_restrict') \\
tex    \addlinespace
tex    \addlinespace
tex	   \multicolumn{2}{l}{Implied Effects on \$f\$ and \$u_{ss}\$} & & & & \\
tex		& \$\Delta\$ log(\$f\$) & `jfrate_rat_all' & `jfrate_rat_restrict' & `jfrate_sep_all' & `jfrate_sep_restrict' \\
tex		& \$\Delta u_{ss}\$ (percentage points) & `ss_urate_diff_rat_all' & `ss_urate_diff_rat_restrict' & `ss_urate_diff_sep_all' & `ss_urate_diff_sep_restrict' \\
tex    \addlinespace
tex    \addlinespace
tex    \multicolumn{2}{l}{Seasonal Adjustment as Ratios} & \$\checkmark\$ & \$\checkmark\$  & & \\
tex    \multicolumn{2}{l}{Seasonal Adjustment Separately} & & & \$\checkmark\$ & \$\checkmark\$ \\
tex    \multicolumn{2}{l}{Full Comparison Group} & & \$\checkmark\$ & & \$\checkmark\$ \\
tex \midrule
tex \$N\$ & & `N_rat_all' & `N_rat_restrict' & `N_sep_all' & `N_sep_restrict' \\ \bottomrule \bottomrule
tex \end{tabular}
texdoc close
		
forval k=1/`timecount' {
	local sa_method: word `k' of `satype'
	local comp_type: word `k' of `compgroup'

		foreach num in 50 55 60 { 
			// local for micro effect:
			local micro_`sa_method'_`comp_type'_`num' = `b_VU_`sa_method'_`comp_type'' + (1/(1-0.`num'))*`b_HV_`sa_method'_`comp_type''
			
			// local for theta (increase in market tightness)
			local theta_`sa_method'_`comp_type'_`num' = `b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type'_`num''
				
			// calclate job finding rate
			local jfrate_`sa_method'_`comp_type'_`num' = `micro_`sa_method'_`comp_type'_`num'' + (0.`num'*(`theta_`sa_method'_`comp_type'_`num''))
					
			// calculate share of change in JFR due to equilibrium
			if `jfrate_`sa_method'_`comp_type'_`num'' >= 0 {
				local equil_share_`sa_method'_`comp_type'_`num' = 100*((0.`num'*(`b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type'_`num''))/`jfrate_`sa_method'_`comp_type'_`num'')
			}
			if `jfrate_`sa_method'_`comp_type'_`num'' < 0 {
				local equil_share_`sa_method'_`comp_type'_`num' = -100*((0.`num'*(`b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type'_`num''))/`jfrate_`sa_method'_`comp_type'_`num'')	
			}

			// format numbers
			local micro_`sa_method'_`comp_type'_`num': di %5.3f `micro_`sa_method'_`comp_type'_`num''
			local theta_`sa_method'_`comp_type'_`num': di %5.3f `theta_`sa_method'_`comp_type'_`num''
			local jfrate_`sa_method'_`comp_type'_`num': di %4.3f `jfrate_`sa_method'_`comp_type'_`num''
			local equil_share_`sa_method'_`comp_type'_`num': di %3.0f `equil_share_`sa_method'_`comp_type'_`num''
			
			di "Alpha = `num'"
			di "Search Effort: `micro_`sa_method'_`comp_type'_`num''"
			di "Theta: `theta_`sa_method'_`comp_type'_`num''"
			di "Equil Share: `equil_share_`sa_method'_`comp_type'_`num''"
			
			***** Put micro, theta, Equil-Share in globals to be analzyed *****
			global macro_`sa_method'_`comp_type'_`num' = `equil_share_`sa_method'_`comp_type'_`num''
			global theta_`sa_method'_`comp_type'_`num' = `theta_`sa_method'_`comp_type'_`num''
			global micro_`sa_method'_`comp_type'_`num' = `micro_`sa_method'_`comp_type'_`num''
			}
		********** Put it into Tex **************************************	
		texdoc init "${tables}decomp_VU_sHV_`sa_method'_`comp_type'_bench.tex", replace force
		tex  0.50  & `micro_`sa_method'_`comp_type'_50' & `theta_`sa_method'_`comp_type'_50' & `equil_share_`sa_method'_`comp_type'_50'\%  \\
		tex  0.55  & `micro_`sa_method'_`comp_type'_55' & `theta_`sa_method'_`comp_type'_55' & `equil_share_`sa_method'_`comp_type'_55'\%  \\
		tex  0.60  & `micro_`sa_method'_`comp_type'_60' & `theta_`sa_method'_`comp_type'_60' & `equil_share_`sa_method'_`comp_type'_60'\%  \\ 	
		texdoc close

		}

end

/******************************************************************************/
* 		Table 4: M-bar for regressions 
/******************************************************************************/
cap drop prog do_table4
prog define do_table4

*************
** seasonally adjusted as ratio
*************
use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear

// drop states that also changed UI policies during this time or for which there isn't sufficient data
drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
	"HAWAII", "MASSACHUSETTS","DISTRICT OF COLUMBIA")
	
// get the pre-treatment mean for Missouri
egen idd = group(state)

keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
// merge on "restricted controls" flag
merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen

// Merge on UI trust fund for benchmark controls	
merge m:1 state using "${statedata}ui_trust_fund.dta"

drop if _merge==2 // drops U.S. V.I. & SC, MI, MA, GA, FL 
		// note: _merge ==1 means state had no debt 
replace ui_debt=0 if ui_debt==.
drop _merge

xtset idd yrqtr	// set as a time series			
	
* Create a treatment dummy
gen D = (state=="MISSOURI")
gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

eststo clear

// create flag for benchmark state 
gen benchmark = (peak_near_MO==1 & ui_debt>0)
*****
* V/U; Ratio
*****
********
* Benchmark Comparisons
********	
	reghdfe log_newv_over_unemp b204.Dyearq if benchmark==1, ///
		a(idd yrqtr) cluster(idd) nocon
	* first period
	honestdid, pre(1/4) post(6/11) mvec(0.7(0.1)1)	// breaks down at 0.9
	* all periods
	matrix l_vec = 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 
	honestdid, l_vec(l_vec) pre(1/4) post(6/11) mvec(0.4(0.1)0.7)
			// breaks down at 0.6	
			
********
* All Comparisons
********
	reghdfe log_newv_over_unemp b204.Dyearq, a(idd yrqtr) cluster(idd) nocon

	* first period
	honestdid, pre(1/4) post(6/11) mvec(1.2(0.1)1.4)	// breaks down at 1.4

	* all periods
	matrix l_vec = 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 
	honestdid, l_vec(l_vec) pre(1/4) post(6/11) mvec(0.8(0.1)1) gridPoints(100)
			// breaks down at 0.9
	
*****
* H/V; Ratio
*****
********
* Benchmark Comparisons
********	
	reghdfe log_newsh_over_newv b204.Dyearq if benchmark==1, ///
		a(idd yrqtr) cluster(idd) nocon
	* first period
	honestdid, pre(1/4) post(6/11) mvec(1.1(0.1)1.4)	// breaks down at 1.3
	* all periods
	matrix l_vec = 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 
	honestdid, l_vec(l_vec) pre(1/4) post(6/11) mvec(0.2(0.1)0.4)
		// breaks down at 0.3
	
********
* All Comparisons
********
	reghdfe log_newsh_over_newv b204.Dyearq, a(idd yrqtr) cluster(idd) nocon
	* first period
	honestdid, pre(1/4) post(6/11) mvec(1.3(0.1)1.7)	// breaks down at 1.6
	* all periods
	matrix l_vec = 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 
	honestdid, l_vec(l_vec) pre(1/4) post(6/11) mvec(0.1(0.1)0.4) gridPoints(100)
		// breaks down at 0.3
		
*************
** seasonally adjusted separately
*************	
use	"${statedata}synth_ready_quarterly.dta", clear

// drop states that also changed UI policies during this time or for which there isn't sufficient data
drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
	"HAWAII", "MASSACHUSETTS","DISTRICT OF COLUMBIA")
	
// get the pre-treatment mean for Missouri
egen idd = group(state)

keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
// merge on "restricted controls" flag
merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen

// Merge on UI trust fund for benchmark controls	
merge m:1 state using "${statedata}ui_trust_fund.dta"

drop if _merge==2 // drops U.S. V.I. & SC, MI, MA, GA, FL 
		// note: _merge ==1 means state had no debt 
replace ui_debt=0 if ui_debt==.
drop _merge

xtset idd yrqtr	// set as a time series			
	
* Create a treatment dummy
gen D = (state=="MISSOURI")
gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

eststo clear
// create flag for benchmark state 
gen benchmark = (peak_near_MO==1 & ui_debt>0)
*****
* V/U; separately adjusted
*****
********
* Benchmark Comparisons
********	
	reghdfe log_newv_over_unemp b204.Dyearq if benchmark==1, ///
		a(idd yrqtr) cluster(idd) nocon
	* first period
	honestdid, pre(1/4) post(6/11) mvec(0.8(0.1)1.2)	// breaks down at 0.9
	* all periods
	matrix l_vec = 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 
	honestdid, l_vec(l_vec) pre(1/4) post(6/11) mvec(0.4(0.1)0.7) 
		// breaks down at 0.6

********
* All Comparisons
********
	reghdfe log_newv_over_unemp b204.Dyearq, a(idd yrqtr) cluster(idd) nocon
	* first period
	honestdid, pre(1/4) post(6/11) mvec(1.3(0.1)1.5)	// breaks down at 1.5
	* all periods
	matrix l_vec = 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 
	honestdid, l_vec(l_vec) pre(1/4) post(6/11) mvec(0.7(0.1)0.9) 
		// breaks down at 0.8
		
*****
* H/V; Ratio
*****
********
* Benchmark Comparisons
********	
	reghdfe log_newsh_over_newv b204.Dyearq if benchmark==1, ///
		a(idd yrqtr) cluster(idd) nocon
	* first period
	honestdid, pre(1/4) post(6/11) mvec(0.8(0.1)1.2)	// breaks down at 1.0
	* all periods
	matrix l_vec = 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 
	honestdid, l_vec(l_vec) pre(1/4) post(6/11) mvec(0.1(0.1)0.2)
		// breaks down at 0.2
********
* All Comparisons
********
	reghdfe log_newsh_over_newv b204.Dyearq, a(idd yrqtr) cluster(idd) nocon
	* first period
	honestdid, pre(1/4) post(6/11) mvec(1.5(0.1)2.1)	// breaks down at 1.7
	* all periods
	matrix l_vec = 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 \ 0.1667 
	honestdid, l_vec(l_vec) pre(1/4) post(6/11) mvec(0.1(0.1)0.3) gridPoints(100)
		// breaks down at 0.2

end


/******************************************************************************/
* 		Table 5: Effect of UI Cut on JF & Sep Rates (Quarterly)
/******************************************************************************/
cap drop prog do_table5
prog define do_table5


**** NOTE: all = bench, restrict = all


	* step 1: read in CPS flows
	use "${statedata}f_rate_state_cps_sa_shimeradj.dta", clear
	
	// merge f rate with s rate
	merge 1:1 ym code month year statename abbv statenameupper fips using ///
		"${statedata}s_rate_state_cps_sa_shimeradj.dta", nogen

		
	// create static DID variables
	gen MO = (abbv=="MO")
	gen post = (ym > ym(2011,3))
	gen MO_post = MO*post
	
	* keep proper time period 
	keep if inrange(ym, ym(2010,1), ym(2012,9))
	
	* rename flow rates
	ren job_finding_rate find_rate
	ren separation_rate sep_rate
	ren statenameupper state 
	
	// drop states that also changed UI policies during this time or not sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA", ///
	"GEORGIA", "HAWAII", "MASSACHUSETTS","DISTRICT OF COLUMBIA")

	// create numeric ID
	egen idd = group(state)
	
	// create a quarterly variable
	gen quarter = 1 if inrange(month,1,3)
	replace quarter = 2 if inrange(month,4,6)
	replace quarter = 3 if inrange(month,7,9)
	replace quarter = 4 if inrange(month,10,12)
	gen yq=yq(year,quarter)
	format yq %tq
	
	* Create a treatment variable
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2011M3 if D=0
	
	collapse (mean) find_rate sep_rate Dyearq MO_post, by(abbv idd state year quarter yq)
	replace find_rate 	= log(find_rate)
	replace sep_rate 	= log(sep_rate)
	xtset idd yq	// set as a time series	
	eststo clear
	
	* what type of comparison group
	local compgroup  restrict all
	local timecount: word count(`compgroup')
	forval k=1/`timecount' {			
		local comp_type: word `k' of `compgroup'
		
		// merge "peak unemployment rate" and UI trust fund info
		merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
		merge m:1 state using "${statedata}ui_trust_fund.dta"

		drop if _merge==2 // drops U.S. V.I.

		replace ui_debt=0 if ui_debt==.
		drop _merge

		// whether or not to use benchmark comparison set
		if "`comp_type'"=="all" {
			
			keep if peak_near_MO==1 & ui_debt>0
		}
		
		* which flow are we measuring? (UE or EU)?
		local flowtype find_rate sep_rate
		foreach var in `flowtype' {	// loop over EU and UE
			// simple TWFE
			reghdfe `var' MO_post, a(yq idd) vce(cluster idd)
				local b_`var'_`comp_type' = _b[MO_post]	// store beta coefficient
				local oneway_`var'_`comp_type' = _se[MO_post]	// store standard error
				local N_`comp_type' = e(N)		
				// format both the beta and SE
				if "`var'"=="find_rate"{
					local b_`var'_`comp_type' : di %4.3f `b_`var'_`comp_type''
					local oneway_`var'_`comp_type' : di %4.3f `oneway_`var'_`comp_type''
				}
				if "`var'"=="sep_rate"{
					local b_`var'_`comp_type' : di %5.4f `b_`var'_`comp_type''
					local oneway_`var'_`comp_type' : di %5.4f `oneway_`var'_`comp_type''
				}
				local N_`comp_type' : di %5.0fc `N_`comp_type''
			reghdfe `var' MO_post, a(yq idd) vce(cluster yq idd)
			local twoway_`var'_`comp_type' = _se[MO_post]	// store standard error
				// format the SE
				if "`var'"=="find_rate"{
					local twoway_`var'_`comp_type' : di %4.3f `twoway_`var'_`comp_type''
				}
				if "`var'"=="sep_rate"{
					local twoway_`var'_`comp_type' : di %5.4f `twoway_`var'_`comp_type''			
				}
		
		}
	
	}
	
	*** Write .tex table for main effects (job-finding and separation)
	texdoc init "${tables}panel_regressions_s_f_rate_quarterly_bench.tex", replace force
	tex \begin{tabular}{lrcc} \toprule \toprule
	tex     & &  (1) & (2) \\ \midrule 
	tex    \multicolumn{2}{l}{A. \textit{Job Finding Rate}} & & \\
	tex    & $\hat{\beta}_{MO\_post}$ & `b_find_rate_all' & `b_find_rate_restrict' \\
	tex    & One-way clustered SE & (`oneway_find_rate_all') & (`oneway_find_rate_restrict') \\
	tex    & Two-way clustered SE & (`twoway_find_rate_all') & (`twoway_find_rate_restrict') \\
	tex    \addlinespace
	tex    \multicolumn{2}{l}{B. \textit{Job Separation Rate}} & & \\
	tex    & $\hat{\beta}_{MO\_post}$ & `b_sep_rate_all' & `b_sep_rate_restrict' \\
	tex    & One-way clustered SE & (`oneway_sep_rate_all') & (`oneway_sep_rate_restrict') \\
	tex    & Two-way clustered SE & (`twoway_sep_rate_all') & (`twoway_sep_rate_restrict') \\
	tex    \addlinespace
	tex    \addlinespace
	tex    \multicolumn{2}{l}{Full Comparison Group} & & \$\checkmark\$ \\
	tex \midrule
	tex \$N\$ & & `N_all' & `N_restrict' \\ \bottomrule \bottomrule

	tex \end{tabular}
	texdoc close

end


/******************************************************************************/
* 		Table 6: Effect of UI Cut and Decomposition with Political Control Units
/******************************************************************************/
cap drop do_tables6and7
prog define do_tables6and7
********************************************************************************
*****			SEPARATE
********************************************************************************
use	"${statedata}synth_ready_quarterly.dta", clear

	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","DISTRICT OF COLUMBIA")
		
	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	xtset fipsstate yrqtr	// set as a time series			
	
	// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
	// merge to 2008 US Presidential Election Data 
	merge m:1 fipsstate using "${statedata}2008_presidential_election_voteshare.dta"
	keep if _merge==3	// drops FL, AK, MI, SC, GA, MA, DC 
	drop _merge 
	// merge to 2011 state legislature control data 
	merge m:1 fipsstate using "${statedata}state_leg_control_KMM.dta"
	keep if _merge==3	// drops FL, AK, MI, SC, GA, MA, DC 
	drop _merge 

	
	// control groups
	gen joint_ctr_grp2 = (peak_near_MO==1 & politic_min1leg_GOP_2011==1)
	gen joint_ctr_grp3 = (peak_near_MO==1 & MO_2008_demshare_within20==1)		

// loop over 2 types of control groups
forval k=2/3{
********************	
*****   newV/U
********************
***		reg on MO x Post, two way FE; cluster at the state level
	reghdfe log_newv_over_unemp MO_post if joint_ctr_grp`k'==1, a(yrqtr fipsstate) vce(cluster fipsstate)
		local b_VU_sep_comp`k' = _b[MO_post]	// store beta coefficient
		local oneway_VU_sep_comp`k' = _se[MO_post]	// store standard error
		local N_sep_comp`k' = e(N)

		// format both the beta and SE
		local b_VU_sep_comp`k' : di %4.3f `b_VU_sep_comp`k''
		local oneway_VU_sep_comp`k' : di %4.3f `oneway_VU_sep_comp`k''
		local N_sep_comp`k' : di %5.0fc `N_sep_comp`k''			
				
	*****  reg newV/U on MO x Post, two way FE; cluster at the state & year-quarter level
	qui reghdfe log_newv_over_unemp MO_post if joint_ctr_grp`k'==1, a(yrqtr fipsstate) vce(cluster yrqtr fipsstate)
		local twoway_VU_sep_comp`k' = _se[MO_post]	// store standard error
		// format the SE
		local twoway_VU_sep_comp`k' : di %4.3f `twoway_VU_sep_comp`k''
		
********************	
*****   stable H/ new V
********************
***		reg on MO x Post, two way FE; cluster at the state level
	reghdfe log_newsh_over_newv MO_post if joint_ctr_grp`k'==1, a(yrqtr fipsstate) vce(cluster fipsstate)
		local b_HV_sep_comp`k' = _b[MO_post]	// store beta coefficient
		local oneway_HV_sep_comp`k' = _se[MO_post]	// store standard error

		// format both the beta and SE
		local b_HV_sep_comp`k' : di %4.3f `b_HV_sep_comp`k''
		local oneway_HV_sep_comp`k' : di %4.3f `oneway_HV_sep_comp`k''
				
	*****  reg newV/U on MO x Post, two way FE; cluster at the state & year-quarter level
	qui reghdfe log_newsh_over_newv MO_post if joint_ctr_grp`k'==1, a(yrqtr fipsstate) vce(cluster yrqtr fipsstate)
		local twoway_HV_sep_comp`k' = _se[MO_post]	// store standard error
		// format the SE
		local twoway_HV_sep_comp`k' : di %4.3f `twoway_HV_sep_comp`k''
		
}

forval k=2/3{
****************************************************
**	Calculate Effect on Job Finding Rate, Steady-State Unemployment

	*Step 1: Obtain UE and EU flows that are adjusted for time aggregation bias
		use "${statedata}f_rate_state_cps_sa_shimeradj.dta", clear
		// only keep Missouri observations during relevant time span
		keep if statenameupper=="MISSOURI" & inrange(ym,ym(2011,4),ym(2012,9))
		tsset ym 	// set as time series(
		// extract the mean JFR in the quarter we want
			qui summ job_finding_rate
			local jfr_mean = `r(mean)'
			
		// same thing but for separation rate (Shimer adj EU rate)
		use "${statedata}s_rate_state_cps_sa_shimeradj.dta", clear
			// only keep Missouri observations during relevant time span
			keep if statenameupper=="MISSOURI" & inrange(ym,ym(2011,4),ym(2012,9))
			tsset ym 	// set as time series
		// extract the mean separation rate in the quarter we want
			summ separation_rate
			local sep_mean = `r(mean)'
			
		// create observed steady state unemployment rate
			local normal_ss_urate = 100*`sep_mean'/(`sep_mean'+ `jfr_mean')	
	
			// local for micro effect:
			local micro_sep_comp`k' = `b_VU_sep_comp`k'' + (1/(1-0.3))*`b_HV_sep_comp`k''
			
			// local for theta (increase in market tightness):
			local theta_sep_comp`k' = `b_VU_sep_comp`k''-`micro_sep_comp`k''
				
			// calclate job finding rate:
			local jfrate_sep_comp`k' = `micro_sep_comp`k'' + (0.3*(`theta_sep_comp`k''))

			// calculate how much JFR Δ & new URate as result of policy:
			local ctrf_jfr_sep_comp`k' = `jfr_mean'*exp((-1)*`jfrate_sep_comp`k'')
			local ctrf_ss_urate_sep_comp`k' = 100*`sep_mean'/(`sep_mean'+ `ctrf_jfr_sep_comp`k'')
			// lastly, calculate the difference between the normal and ctrf URates (or JFR)
			local ss_urate_diff_sep_comp`k' = `normal_ss_urate' - `ctrf_ss_urate_sep_comp`k''			

			// format numbers	
			local jfrate_sep_comp`k': di %4.3f `jfrate_sep_comp`k''
			local ss_urate_diff_sep_comp`k': di %3.2f `ss_urate_diff_sep_comp`k''	
			
}

********************************************************************************
*****			RATIO
********************************************************************************
use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear

	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","DISTRICT OF COLUMBIA")
		
	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	xtset fipsstate yrqtr	// set as a time series			

	// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
	// merge to 2008 US Presidential Election Data 
	merge m:1 fipsstate using "${statedata}2008_presidential_election_voteshare.dta"
	keep if _merge==3	// drops FL, AK, MI, SC, GA, MA, DC 
	drop _merge 
	// merge to 2011 state legislature control data 
	merge m:1 fipsstate using "${statedata}state_leg_control_KMM.dta"
	keep if _merge==3	// drops FL, AK, MI, SC, GA, MA, DC 
	drop _merge 
	
	// control groups
	gen joint_ctr_grp2 = (peak_near_MO==1 & politic_min1leg_GOP_2011==1)
	gen joint_ctr_grp3 = (peak_near_MO==1 & MO_2008_demshare_within20==1)	

// loop over 2 types of control groups
forval k=2/3{
********************	
*****   newV/U
********************
***		reg on MO x Post, two way FE; cluster at the state level
	reghdfe log_newv_over_unemp MO_post if joint_ctr_grp`k'==1, a(yrqtr fipsstate) vce(cluster fipsstate)
		local b_VU_rat_comp`k' = _b[MO_post]	// store beta coefficient
		local oneway_VU_rat_comp`k' = _se[MO_post]	// store standard error
		local N_rat_comp`k' = e(N)

		// format both the beta and SE
		local b_VU_rat_comp`k' : di %4.3f `b_VU_rat_comp`k''
		local oneway_VU_rat_comp`k' : di %4.3f `oneway_VU_rat_comp`k''
		local N_rat_comp`k' : di %5.0fc `N_rat_comp`k''			
				
	*****  reg newV/U on MO x Post, two way FE; cluster at the state & year-quarter level
	qui reghdfe log_newv_over_unemp MO_post if joint_ctr_grp`k'==1, a(yrqtr fipsstate) vce(cluster yrqtr fipsstate)
		local twoway_VU_rat_comp`k' = _se[MO_post]	// store standard error
		// format the SE
		local twoway_VU_rat_comp`k' : di %4.3f `twoway_VU_rat_comp`k''
		
********************	
*****   stable H/ new V
********************
***		reg on MO x Post, two way FE; cluster at the state level
	reghdfe log_newsh_over_newv MO_post if joint_ctr_grp`k'==1, a(yrqtr fipsstate) vce(cluster fipsstate)
		local b_HV_rat_comp`k' = _b[MO_post]	// store beta coefficient
		local oneway_HV_rat_comp`k' = _se[MO_post]	// store standard error

		// format both the beta and SE
		local b_HV_rat_comp`k' : di %4.3f `b_HV_rat_comp`k''
		local oneway_HV_rat_comp`k' : di %4.3f `oneway_HV_rat_comp`k''
				
	*****  reg newV/U on MO x Post, two way FE; cluster at the state & year-quarter level
	qui reghdfe log_newsh_over_newv MO_post if joint_ctr_grp`k'==1, a(yrqtr fipsstate) vce(cluster yrqtr fipsstate)
		local twoway_HV_rat_comp`k' = _se[MO_post]	// store standard error
		// format the SE
		local twoway_HV_rat_comp`k' : di %4.3f `twoway_HV_rat_comp`k''
		
}

forval k=2/3{
****************************************************
**	Calculate Effect on Job Finding Rate, Steady-State Unemployment

	*Step 1: Obtain UE and EU flows that are adjusted for time aggregation bias
		use "${statedata}f_rate_state_cps_sa_shimeradj.dta", clear
		// only keep Missouri observations during relevant time span
		keep if statenameupper=="MISSOURI" & inrange(ym,ym(2011,4),ym(2012,9))
		tsset ym 	// set as time series(
		// extract the mean JFR in the quarter we want
			qui summ job_finding_rate
			local jfr_mean = `r(mean)'
			
		// same thing but for separation rate (Shimer adj EU rate)
		use "${statedata}s_rate_state_cps_sa_shimeradj.dta", clear
			// only keep Missouri observations during relevant time span
			keep if statenameupper=="MISSOURI" & inrange(ym,ym(2011,4),ym(2012,9))
			tsset ym 	// set as time series
		// extract the mean separation rate in the quarter we want
			summ separation_rate
			local sep_mean = `r(mean)'
			
		// create observed steady state unemployment rate
			local normal_ss_urate = 100*`sep_mean'/(`sep_mean'+ `jfr_mean')	
	
			// local for micro effect:
			local micro_rat_comp`k' = `b_VU_rat_comp`k'' + (1/(1-0.3))*`b_HV_rat_comp`k''
			
			// local for theta (increase in market tightness):
			local theta_rat_comp`k' = `b_VU_rat_comp`k''-`micro_rat_comp`k''
				
			// calclate job finding rate:
			local jfrate_rat_comp`k' = `micro_rat_comp`k'' + (0.3*(`theta_rat_comp`k''))

			// calculate how much JFR Δ & new URate as result of policy:
			local ctrf_jfr_rat_comp`k' = `jfr_mean'*exp((-1)*`jfrate_rat_comp`k'')
			local ctrf_ss_urate_rat_comp`k' = 100*`sep_mean'/(`sep_mean'+ `ctrf_jfr_rat_comp`k'')
			// lastly, calculate the difference between the normal and ctrf URates (or JFR)
			local ss_urate_diff_rat_comp`k' = `normal_ss_urate' - `ctrf_ss_urate_rat_comp`k''			

			// format numbers	
			local jfrate_rat_comp`k': di %4.3f `jfrate_rat_comp`k''
			local ss_urate_diff_rat_comp`k': di %3.2f `ss_urate_diff_rat_comp`k''	
			
}
	

	
// *** Write .tex table for main effects (all New Hires & New Vacancies)
texdoc init "${tables}panel_regressions_beta_pol_k_controls.tex", replace force
tex \begin{tabular}{lrcccc} \toprule \toprule
tex     & &  (1) & (2) & (3) & (4)  \\ \midrule 
tex    \multicolumn{2}{l}{A. \$Vacancies / Unemployment\$} & & & \\
tex    & $\hat{\beta}_{MO\_post}$ &  `b_VU_rat_comp2' & `b_VU_rat_comp3' &  `b_VU_sep_comp2' & `b_VU_sep_comp3' \\
tex    & One-way clustered SE & (`oneway_VU_rat_comp2') & (`oneway_VU_rat_comp3') & (`oneway_VU_sep_comp2') & (`oneway_VU_sep_comp3')  \\
tex    & Two-way clustered SE &  (`twoway_VU_rat_comp2') & (`twoway_VU_rat_comp3') &  (`twoway_VU_sep_comp2') & (`twoway_VU_sep_comp3') \\
tex    \addlinespace
tex    \multicolumn{2}{l}{B. \$Hires / Vacancies\$} & & & \\
tex    & $\hat{\beta}_{MO\_post}$ &  `b_HV_rat_comp2' & `b_HV_rat_comp3' & `b_HV_sep_comp2' & `b_HV_sep_comp3' \\
tex    & One-way clustered SE &  (`oneway_HV_rat_comp2') & (`oneway_HV_rat_comp3') &  (`oneway_HV_sep_comp2') & (`oneway_HV_sep_comp3') \\
tex    & Two-way clustered SE &  (`twoway_HV_rat_comp2') & (`twoway_HV_rat_comp3') &  (`twoway_HV_sep_comp2') & (`twoway_HV_sep_comp3') \\
tex    \addlinespace
tex    \addlinespace
tex	   \multicolumn{2}{l}{Implied Effects on \$f\$ and \$u_{ss}\$} & & &  \\
tex		& \$\Delta\$ log(\$f\$) &  `jfrate_rat_comp2' & `jfrate_rat_comp3'  & `jfrate_sep_comp2' & `jfrate_sep_comp3' \\
tex		& \$\Delta u_{ss}\$ (percentage points) &  `ss_urate_diff_rat_comp2' & `ss_urate_diff_rat_comp3'  & `ss_urate_diff_sep_comp2' & `ss_urate_diff_sep_comp3' \\
tex    \addlinespace
tex    \addlinespace
tex    \multicolumn{2}{l}{Seasonal Adjustment as Ratios} &  \$\checkmark\$  & \$\checkmark\$ & &  \\
tex    \multicolumn{2}{l}{Seasonal Adjustment Separately} &  & & \$\checkmark\$ & \$\checkmark\$   \\
tex	   \multicolumn{2}{l}{\textit{Control Units}:} & & & \\
tex	   \multicolumn{2}{l}{Unemp Peak Near MO's} & \$\checkmark\$ & \$\checkmark\$ & \$\checkmark\$ & \$\checkmark\$ \\
tex	   \multicolumn{2}{l}{GOP House and/or Senate} & \$\checkmark\$ & & \$\checkmark\$ & \\
tex	   \multicolumn{2}{l}{Obama Voteshare Near MO's} & & \$\checkmark\$ & & \$\checkmark\$ \\
tex \midrule
tex \$N\$ & & `N_rat_comp2' & `N_rat_comp3' & `N_sep_comp2' & `N_sep_comp3' \\ \bottomrule \bottomrule
tex \end{tabular}
texdoc close




	
local satype sep rat
local timecount: word count(`satype')
		
forval j=1/`timecount' {
	local sa_method: word `j' of `satype'

	forval k=2/3 {
		foreach num in 50 55 60 { 
			// local for micro effect:
			local micro_`sa_method'_comp`k'_`num' = `b_VU_`sa_method'_comp`k'' + ///
						(1/(1-0.`num'))*`b_HV_`sa_method'_comp`k''
			
			// local for theta (increase in market tightness)
			local theta_`sa_method'_comp`k'_`num' = `b_VU_`sa_method'_comp`k'' - ///
							`micro_`sa_method'_comp`k'_`num''
				
			// calclate job finding rate
			local jfrate_`sa_method'_comp`k'_`num' = `micro_`sa_method'_comp`k'_`num'' +  ///
							(0.`num'*(`theta_`sa_method'_comp`k'_`num''))
					
			// calculate share of change in JFR due to equilibrium
			if `jfrate_`sa_method'_comp`k'_`num'' >= 0 {
				local equil_share_`sa_method'_comp`k'_`num' = 100*((0.`num'*(`b_VU_`sa_method'_comp`k''-`micro_`sa_method'_comp`k'_`num''))/`jfrate_`sa_method'_comp`k'_`num'')
			}
			if `jfrate_`sa_method'_comp`k'_`num'' < 0 {
				local equil_share_`sa_method'_comp`k'_`num' = ///
						-100*((0.`num'*(`b_VU_`sa_method'_comp`k''-`micro_`sa_method'_comp`k'_`num''))/`jfrate_`sa_method'_comp`k'_`num'')	
			}

			// format numbers
			local micro_`sa_method'_comp`k'_`num': di %5.3f `micro_`sa_method'_comp`k'_`num''
			local theta_`sa_method'_comp`k'_`num': di %5.3f `theta_`sa_method'_comp`k'_`num''
			local jfrate_`sa_method'_comp`k'_`num': di %4.3f `jfrate_`sa_method'_comp`k'_`num''
			local equil_share_`sa_method'_comp`k'_`num': di %3.0f `equil_share_`sa_method'_comp`k'_`num''
			
			di "Alpha = `num'"
			di "Search Effort: `micro_`sa_method'_comp`k'_`num''"
			di "Theta: `theta_`sa_method'_comp`k'_`num''"
			di "Equil Share: `equil_share_`sa_method'_comp`k'_`num''"
			
			***** Put micro, theta, Equil-Share in globals to be analzyed *****
			global macro_`sa_method'_comp`k'_`num' = `equil_share_`sa_method'_comp`k'_`num''
			global theta_`sa_method'_comp`k'_`num' = `theta_`sa_method'_comp`k'_`num''
			global micro_`sa_method'_comp`k'_`num' = `micro_`sa_method'_comp`k'_`num''

			}
		********** Put it into Tex **************************************	
		texdoc init "${tables}decomp_VU_sHV_kurt_`sa_method'_comp`k'.tex", replace force
		tex  0.50  & `micro_`sa_method'_comp`k'_50' & `theta_`sa_method'_comp`k'_50' & `equil_share_`sa_method'_comp`k'_50'\%  \\
		tex  0.55  & `micro_`sa_method'_comp`k'_55' & `theta_`sa_method'_comp`k'_55' & `equil_share_`sa_method'_comp`k'_55'\%  \\
		tex  0.60  & `micro_`sa_method'_comp`k'_60' & `theta_`sa_method'_comp`k'_60' & `equil_share_`sa_method'_comp`k'_60'\%  \\ 	
		texdoc close
		}	
	}	
end 	



/******************************************************************************/
*  Figure A.4: Dynamic Effect of UI Cut; Alternate Set of Control States (Politics)
/******************************************************************************/

cap drop prog do_figureA4
prog define do_figureA4
**==================================================================**
**==================================================================**
**==================================================================**

*outcome variables
local sa_vars log_newsh_over_newv log_newv_over_unemp

*seasonal adjustment
local satype rat /*sep*/

local timecount: word count(`satype')
**==================================================================**
**==================================================================**
**==================================================================**

forval k=1/`timecount' {
local sa_method: word `k' of `satype'

	local sa_longform "ratio"
	use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear
}
	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"HAWAII", "MASSACHUSETTS","DISTRICT OF COLUMBIA")
	
	// get the pre-treatment mean for Missouri
	egen idd = group(state)

	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	xtset idd yrqtr	// set as a time series			
	
	// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
	// merge to 2008 US Presidential Election Data 
	merge m:1 fipsstate using "${statedata}2008_presidential_election_voteshare.dta"
	keep if _merge==3	// drops FL, AK, MI, SC, GA, MA, DC 
	drop _merge 
	// merge to 2011 state legislature control data 
	merge m:1 fipsstate using "${statedata}state_leg_control_KMM.dta"
	keep if _merge==3	// drops FL, AK, MI, SC, GA, MA, DC 
	drop _merge 

	
	//	merge ui trust fund data
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.
	
	replace ui_debt=ui_debt*1000000
	replace ui_debt=0 if ui_debt==.
	gen 	ui_debt_perpop = ui_debt/exp(lnpop)
	drop _merge
	
	// control groups
	//		joint_ctr_grp = near_peak_MO + GOP controls one house of legislature (N=13)
	gen joint_ctr_grp = (peak_near_MO==1 & politic_min1leg_GOP_2011==1)
	
	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

	eststo clear
	foreach var in `sa_vars' {	// loop over V/U and H/V
		// need abbreviations associated with each variable for shortening of local
		if "`var'"=="log_newv_over_unemp"{
			local tag "VU"
			local tagaxis "V/U"
		}
		if "`var'"=="log_newsh_over_newv"{
			local tag "sHV"
			local tagaxis "H/V"
		}
		*****   reg Y on MO x Post, two way FE; cluster at the state level
		di "`var' & BegYr: `thebegyr' BegQtr: `thebegqtr' & SA: `sa_method'"
		reghdfe `var' b204.Dyearq if joint_ctr_grp==1, absorb(idd yrqtr) cluster(idd) noconstant
		coefplot, vertical yline(0) ciopts(recast(rcap)) ylab(, labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("log(`tagaxis')", si(medlarge)) ///
			name(`var'_SA`sa_method'_comp, replace) ///
			baselevels scheme(s1color) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
			202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
			205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
			208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
			211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
			214.Dyearq = `"2013Q3"' 215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray))
		
		gr export "${figures}`tag'_SA`sa_method'_politctrl_grp2.eps", as(eps) replace
	}
}
end	

********************************************************************************
*		Table A.4 & Fig A.5: Effects on MO Labor Market Border State Control Group
********************************************************************************
cap drop do_tablea4_figa5
prog define do_tablea4_figa5


foreach sa in rat sep {
	if "`sa'"=="rat"{
		use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear
	}
	if "`sa'"=="sep"{
		use	"${statedata}synth_ready_quarterly.dta", clear
	}	

	
	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","DISTRICT OF COLUMBIA")
		
	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	xtset fipsstate yrqtr	// set as a time series				
	
	gen surrounding_states = (inlist(state,"KANSAS","NEBRASKA","IOWA","ILLINOIS", ///
									"KENTUCKY","TENNESSEE","ARKANSAS","OKLAHOMA", ///
									"MISSOURI"))
		
********************	
*****   newV/U
********************
	reghdfe log_newv_over_unemp MO_post if surrounding_states==1, a(yrqtr fipsstate) vce(cluster fipsstate)
		local b_VU_`sa' = _b[MO_post]	// store beta coefficient
		local oneway_VU_`sa' = _se[MO_post]	// store standard error
		local N_`sa' = e(N)
		// format both the beta and SE
		local b_VU_`sa' : di %4.3f `b_VU_`sa''
		local oneway_VU_`sa' : di %4.3f `oneway_VU_`sa''
		local N_`sa' : di %5.0fc `N_`sa''			
			
	*****  reg newV/U on MO x Post, two way FE; cluster at the state & year-quarter level
	reghdfe log_newv_over_unemp MO_post if surrounding_states==1, a(yrqtr fipsstate) vce(cluster fipsstate yrqtr)
		local twoway_VU_`sa' = _se[MO_post]	// store standard error
		// format the SE
		local twoway_VU_`sa' : di %4.3f `twoway_VU_`sa''

********************	
*****   stable H/ new V
********************
	reghdfe log_newsh_over_newv MO_post if surrounding_states==1, a(yrqtr fipsstate) vce(cluster fipsstate)	
		local b_HV_`sa' = _b[MO_post]	// store beta coefficient
		local oneway_HV_`sa' = _se[MO_post]	// store standard error
		// format both the beta and SE
		local b_HV_`sa' : di %4.3f `b_HV_`sa''
		local oneway_HV_`sa' : di %4.3f `oneway_HV_`sa''
			
	*****  reg newV/U on MO x Post, two way FE; cluster at the state & year-quarter level
	reghdfe log_newsh_over_newv MO_post if surrounding_states==1, a(yrqtr fipsstate) vce(cluster fipsstate yrqtr)	
		local twoway_HV_`sa' = _se[MO_post]	// store standard error
		// format the SE
		local twoway_HV_`sa' : di %4.3f `twoway_HV_`sa''
		
	************************
	*****  Decomposition
	************************
	// micro effect
		local micro_`sa' = `b_VU_`sa'' + (1/(1-0.55))*`b_HV_`sa''
			
		// local for theta (increase in market tightness)
		local theta_`sa' = `b_VU_`sa''-`micro_`sa''
				
		// calclate job finding rate
		local jfrate_`sa' = `micro_`sa'' + (0.55*(`theta_`sa''))
					
		// share market effects
		local equil_share_`sa' = 100*((0.55*(`b_VU_`sa''-`micro_`sa''))/`jfrate_`sa'')
		
		// format numbers
		local micro_`sa': di %5.3f `micro_`sa''
		local theta_`sa': di %5.3f `theta_`sa''
		local jfrate_`sa': di %4.3f `jfrate_`sa''
		local equil_share_`sa': di %3.0f `equil_share_`sa''
		

		foreach num in 50 55 60 { 
			// local for micro effect:
			local micro_`sa'_`num' = `b_VU_`sa'' + (1/(1-0.`num'))*`b_HV_`sa''
			
			// local for theta (increase in market tightness)
			local theta_`sa'_`num' = `b_VU_`sa''-`micro_`sa'_`num''
				
			// calclate job finding rate
			local jfrate_`sa'_`num' = `micro_`sa'_`num'' + (0.`num'*(`theta_`sa'_`num''))
					
			// calculate share of change in JFR due to equilibrium
			if `jfrate_`sa'_`num'' >= 0 {
				local equil_share_`sa'_`num' = 100*((0.`num'*(`b_VU_`sa''-`micro_`sa'_`num''))/`jfrate_`sa'_`num'')
			}
			if `jfrate_`sa'_`num'' < 0 {
				local equil_share_`sa'_`num' = -100*((0.`num'*(`b_VU_`sa''-`micro_`sa'_`num''))/`jfrate_`sa'_`num'')	
			}

			// format numbers
			local micro_`sa'_`num': di %5.3f `micro_`sa'_`num''
			local theta_`sa'_`num': di %5.3f `theta_`sa'_`num''
			local jfrate_`sa'_`num': di %4.3f `jfrate_`sa'_`num''
			local equil_share_`sa'_`num': di %3.0f `equil_share_`sa'_`num''
			
			di "Alpha = `num'"
			di "Search Effort: `micro_`sa'_`num''"
			di "Theta: `theta_`sa'_`num''"
			di "Equil Share: `equil_share_`sa'_`num''"
			
			***** Put micro, theta, Equil-Share in globals to be analzyed *****
			global macro_`sa'_`num' = `equil_share_`sa'_`num''
			global theta_`sa'_`num' = `theta_`sa'_`num''
			global micro_`sa'_`num' = `micro_`sa'_`num''
		}
		
		
		
		di "Search Effort : `micro_`sa''"
		di "Theta : `theta_`sa''"
		di "JFR : `jfrate_`sa''"
		di "Equil Share : `equil_share_`sa''"
		di ""
		di ""		
}
								

*** Write .tex table for main effects & decomposition
texdoc init "${tables}reg_decomp_surroundingstates.tex", replace force
tex \begin{tabular}{lrcc} \toprule \toprule
tex     & &  (1) & (2) \\ \midrule 
tex    \multicolumn{2}{l}{A. \$Vacancies / Unemployment\$} & & \\
tex    & $\hat{\beta}_{MO\_post}$ & `b_VU_rat' & `b_VU_sep'  \\
tex    & One-way clustered SE & (`oneway_VU_rat') & (`oneway_VU_sep') \\
tex    & Two-way clustered SE & (`twoway_VU_rat') & (`twoway_VU_sep') \\
tex    \addlinespace
tex    \multicolumn{2}{l}{B. \$Hires / Vacancies\$} & & \\
tex    & $\hat{\beta}_{MO\_post}$ & `b_HV_rat' & `b_HV_sep' \\
tex    & One-way clustered SE & (`oneway_HV_rat') & (`oneway_HV_sep') \\
tex    & Two-way clustered SE & (`twoway_HV_rat') & (`twoway_HV_sep') \\
tex    \addlinespace
tex    \addlinespace
tex	   \multicolumn{2}{l}{Implied Effects on Labor Market (\$\alpha\$ = 0.55)} & & \\
tex		& \$\Delta\$ log(\$f\$) & `jfrate_rat' & `jfrate_sep' \\
tex		& \$\Delta\$\$s_t$ & `micro_rat' & `micro_sep' \\
tex		& \$\Delta\$\$\theta_t\$ & `theta_rat' & `theta_sep' \\
tex		& Share Attributable to Macro & `equil_share_rat'\% & `equil_share_sep'\% \\
tex    \addlinespace
tex    \addlinespace
tex    \multicolumn{2}{l}{Seasonally Adjusted as Ratio} &  \$\checkmark\$ & \\
tex    \multicolumn{2}{l}{Seasonally Adjusted Separately}  & &  \$\checkmark\$ \\
tex \midrule
tex \$N\$ & & `N_rat' & `N_sep' \\ \bottomrule \bottomrule
tex \end{tabular}
texdoc close
					
	
**************** 	DYNAMIC 	***********************************	
	
use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear
	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","DISTRICT OF COLUMBIA")
		
	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	xtset fipsstate yrqtr	// set as a time series				
	
	gen surrounding_states = (inlist(state,"KANSAS","NEBRASKA","IOWA","ILLINOIS", ///
									"KENTUCKY","TENNESSEE","ARKANSAS","OKLAHOMA", ///
									"MISSOURI"))
	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0


********************
**** Dynamic V/U 
********************
	// regress V/U on dyanmic TWFE model
	reghdfe log_newv_over_unemp b204.Dyearq if surrounding_states==1, ///
			absorb(fipsstate yrqtr) cluster(fipsstate) noconstant
	eststo VU_surround

	coefplot VU_surround, vertical yline(0) ciopts(recast(rcap)) ylab(, labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("log(V/U)", si(medlarge)) ///
		name(VU_jointgrp_surround, replace) ///
		baselevels scheme(s1color) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
		202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
		205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
		208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
		211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
		214.Dyearq = `"2013Q3"' 215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray))
	gr export "${figures}VU_rat_surrounding_states.eps", as(eps) replace
	
********************
**** Dynamic H/V 
********************
	// regress H/V on dyanmic TWFE model
	reghdfe log_newsh_over_newv b204.Dyearq if surrounding_states==1, ///
			absorb(fipsstate yrqtr) cluster(fipsstate) noconstant
	eststo HV_surround

	coefplot HV_surround, vertical yline(0) ciopts(recast(rcap)) ylab(, labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("log(H/V)", si(medlarge)) ///
		name(HV_jointgrp_surround, replace) ///
		baselevels scheme(s1color) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
		202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
		205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
		208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
		211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
		214.Dyearq = `"2013Q3"' 215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray))
	gr export "${figures}HV_rat_surrounding_states.eps", as(eps) replace

		
end 




********************************************************************************
*		Table A.5: Effect of UI Cut & Decomposition by Varying Start/End Date
********************************************************************************

cap drop prog do_tablea5
prog define do_tablea5


use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear

// drop states that also changed UI policies during this time or for which there isn't sufficient data
drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
	"MASSACHUSETTS","HAWAII","DISTRICT OF COLUMBIA")

keep if inrange(yrqtr,yq(2005,1),yq(2013,4))	// keep broadest possible data range
	
egen idd = group(state) // make state numeric variable 

merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
		// Merge UI trust fund data	
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.
	
	replace ui_debt=0 if ui_debt==.
	drop _merge

	
	keep if peak_near_MO==1	& ui_debt>0  // restrict to "peak near MO"

xtset idd yrqtr	// set as a time series			
	
	** loop over time windows 
	local byears 2010 2009  2008 2007
	local eyears 2012 2013	2013 2013
	local eqtrs     3    1	   1    1
	local windowcount: word count(`eyears')
	
	forval i=1/`windowcount'{
		local byr: word `i' of `byears'	// loop over year-quarters of reg windows
		local eyr: word `i' of `eyears'
		local eqt: word `i' of `eqtrs'

		********************	
		*****   newV/U
		********************
		***		reg on MO x Post, two way FE; cluster at the state level
		qui reghdfe log_newv_over_unemp MO_post if inrange(yrqtr,yq(`byr',1),yq(`eyr',`eqt')), ///
			a(yrqtr idd) vce(cluster idd)
			local b_VU_`byr'Q1_`eyr'`eqt' = _b[MO_post]	// store beta coefficient
			local oneway_VU_`byr'Q1_`eyr'`eqt' = _se[MO_post]	// store standard error
			local N_`byr'Q1_`eyr'`eqt' = e(N)
			// format both the beta and SE
			local b_VU_`byr'Q1_`eyr'`eqt' : di %4.3f `b_VU_`byr'Q1_`eyr'`eqt''
			local oneway_VU_`byr'Q1_`eyr'`eqt' : di %4.3f `oneway_VU_`byr'Q1_`eyr'`eqt''
			local N_`byr'Q1_`eyr'`eqt' : di %5.0fc `N_`byr'Q1_`eyr'`eqt''
			
			** two-way cluster
			qui reghdfe log_newv_over_unemp MO_post if inrange(yrqtr,yq(`byr',1),yq(`eyr',`eqt')), ///
				a(yrqtr idd) vce(cluster yrqtr idd)
				// format SE
				local twoway_VU_`byr'Q1_`eyr'`eqt' = _se[MO_post]	// store standard error
				local twoway_VU_`byr'Q1_`eyr'`eqt' : di %4.3f `twoway_VU_`byr'Q1_`eyr'`eqt''
		
		********************	
		*****   H/V
		********************	
		qui reghdfe log_newsh_over_newv MO_post if inrange(yrqtr,yq(`byr',1),yq(`eyr',`eqt')), ///
			a(yrqtr idd) vce(cluster idd)
			local b_sHV_`byr'Q1_`eyr'`eqt' = _b[MO_post]	// store beta coefficient
			local oneway_sHV_`byr'Q1_`eyr'`eqt' = _se[MO_post]	// store standard error
			// format both the beta and SE
			local b_sHV_`byr'Q1_`eyr'`eqt' : di %4.3f `b_sHV_`byr'Q1_`eyr'`eqt''
			local oneway_sHV_`byr'Q1_`eyr'`eqt' : di %4.3f `oneway_sHV_`byr'Q1_`eyr'`eqt''
	
			** two-way cluster
			qui reghdfe log_newsh_over_newv MO_post if inrange(yrqtr,yq(`byr',1),yq(`eyr',`eqt')), ///
				a(yrqtr idd) vce(cluster yrqtr idd)
				// format SE
				local twoway_sHV_`byr'Q1_`eyr'`eqt' = _se[MO_post]	// store standard error
				local twoway_sHV_`byr'Q1_`eyr'`eqt' : di %4.3f `twoway_sHV_`byr'Q1_`eyr'`eqt''			

			di "VU `byr'-`eyr': `b_VU_`byr'Q1_`eyr'`eqt''"
			di "HV `byr'-`eyr': `b_sHV_`byr'Q1_`eyr'`eqt''"
		
		************************
		*****  Decomposition
		************************
		// micro effect
		local micro_`byr'Q1_`eyr'`eqt' = `b_VU_`byr'Q1_`eyr'`eqt'' ///
										+ (1/(1-0.55))*`b_sHV_`byr'Q1_`eyr'`eqt''
			
		// local for theta (increase in market tightness)
		local theta_`byr'Q1_`eyr'`eqt' = `b_VU_`byr'Q1_`eyr'`eqt''-`micro_`byr'Q1_`eyr'`eqt''
				
		// calclate job finding rate
		local jfrate_`byr'Q1_`eyr'`eqt' = `micro_`byr'Q1_`eyr'`eqt'' ///
										+ (0.55*(`theta_`byr'Q1_`eyr'`eqt''))
					
		// share market effects
		local equil_share_`byr'Q1_`eyr'`eqt' = 100*((0.55*(`b_VU_`byr'Q1_`eyr'`eqt''- ///
						`micro_`byr'Q1_`eyr'`eqt''))/`jfrate_`byr'Q1_`eyr'`eqt'')
		
		// format numbers
		local micro_`byr'Q1_`eyr'`eqt': di %5.3f `micro_`byr'Q1_`eyr'`eqt''
		local theta_`byr'Q1_`eyr'`eqt': di %5.3f `theta_`byr'Q1_`eyr'`eqt''
		local jfrate_`byr'Q1_`eyr'`eqt': di %4.3f `jfrate_`byr'Q1_`eyr'`eqt''
		local equil_share_`byr'Q1_`eyr'`eqt': di %3.0f `equil_share_`byr'Q1_`eyr'`eqt''
			
		di "Search Effort `byr'-`eyr': `micro_`byr'Q1_`eyr'`eqt''"
		di "Theta `byr'-`eyr': `theta_`byr'Q1_`eyr'`eqt''"
		di "JFR `byr'-`eyr': `jfrate_`byr'Q1_`eyr'`eqt''"
		di "Equil Share `byr'-`eyr': `equil_share_`byr'Q1_`eyr'`eqt''"
		di ""
		di ""
}

*** Write .tex table for main effects & decomposition
texdoc init "${tables}reg_decomp_startendtimes_bench.tex", replace force
tex \begin{tabular}{lrcccc} \toprule \toprule
tex     & &  (1) & (2) & (3) & (4) \\ \midrule 
tex    \multicolumn{2}{l}{A. \$Vacancies / Unemployment\$} & & & & \\
tex    & $\hat{\beta}_{MO\_post}$ & `b_VU_2010Q1_20123' & `b_VU_2009Q1_20131' & `b_VU_2008Q1_20131' & `b_VU_2007Q1_20131' \\
tex    & One-way clustered SE & (`oneway_VU_2010Q1_20123') & (`oneway_VU_2009Q1_20131') & (`oneway_VU_2008Q1_20131') & (`oneway_VU_2007Q1_20131') \\
tex    & Two-way clustered SE & (`twoway_VU_2010Q1_20123') & (`twoway_VU_2009Q1_20131') & (`twoway_VU_2008Q1_20131') & (`twoway_VU_2007Q1_20131') \\
tex    \addlinespace
tex    \multicolumn{2}{l}{B. \$Hires / Vacancies\$} & & & & \\
tex    & $\hat{\beta}_{MO\_post}$ & `b_sHV_2010Q1_20123' & `b_sHV_2009Q1_20131' & `b_sHV_2008Q1_20131' & `b_sHV_2007Q1_20131' \\
tex    & One-way clustered SE & (`oneway_sHV_2010Q1_20123') & (`oneway_sHV_2009Q1_20131') & (`oneway_sHV_2008Q1_20131') & (`oneway_sHV_2007Q1_20131') \\
tex    & Two-way clustered SE & (`twoway_sHV_2010Q1_20123') & (`twoway_sHV_2009Q1_20131') & (`twoway_sHV_2008Q1_20131') & (`twoway_sHV_2007Q1_20131') \\
tex    \addlinespace
tex    \addlinespace
tex	   \multicolumn{2}{l}{Implied Effects on Labor Market (\$\alpha\$ = 0.55)} & & & & \\
tex		& \$\Delta\$ log(\$f\$) & `jfrate_2010Q1_20123' & `jfrate_2009Q1_20131' & `jfrate_2008Q1_20131' & `jfrate_2007Q1_20131' \\
tex		& \$\Delta\$\$s_t$ & `micro_2010Q1_20123' & `micro_2009Q1_20131' & `micro_2008Q1_20131' & `micro_2007Q1_20131' \\
tex		& \$\Delta\$\$\theta_t\$ & `theta_2010Q1_20123' & `theta_2009Q1_20131' & `theta_2008Q1_20131' & `theta_2007Q1_20131' \\
tex		& Share Attributable to Macro & `equil_share_2010Q1_20123'\% & `equil_share_2009Q1_20131'\% & `equil_share_2008Q1_20131'\% & `equil_share_2007Q1_20131'\% \\
tex    \addlinespace
tex    \addlinespace
tex    \multicolumn{2}{l}{Beginning Panel} & 2010Q1 & 2009Q1 & 2008Q1 & 2007Q1 \\
tex    \multicolumn{2}{l}{End Panel} & 2012Q3 & 2013Q1 & 2013Q1 & 2013Q1 \\
tex \midrule
tex \$N\$ & & `N_2010Q1_20123' & `N_2009Q1_20131' & `N_2008Q1_20131' & `N_2007Q1_20131' \\ \bottomrule \bottomrule
tex \end{tabular}
texdoc close
	

end


********************************************************************************
** 		Table A.6: Effects of UI Cut with Control Vars
********************************************************************************
cap drop prog do_tablea6
prog define do_tablea6


**** NOTE: all = bench, restrict = all


*seasonal adjustment
local satype sep sep rat rat
* what type of comparison group
local compgroup restrict all  restrict all

local timecount: word count(`compgroup')

forval k=1/`timecount' {
	local sa_method: word `k' of `satype'
	local comp_type: word `k' of `compgroup'

// read in diff file type depending on SA method
if "`sa_method'"=="sep" {
	local sa_longform "separate"
	use	"${statedata}synth_ready_quarterly.dta", clear
}
if "`sa_method'"=="rat" {
	local sa_longform "ratio"
	use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear
}
// drop states that also changed UI policies during this time or for which there isn't sufficient data
drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
	"MASSACHUSETTS","HAWAII","DISTRICT OF COLUMBIA")

keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	
// merge "peak unemployment rate" info
merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen

merge m:1 state using "${statedata}ui_trust_fund.dta"

drop if _merge==2 // drops U.S. V.I.

replace ui_debt=0 if ui_debt==.
drop _merge


	// get the pre-treatment mean for Missouri
	egen idd = group(state)
	qui summ idd
	// put the min and max of state numbers into locals (necessary for permutation test)
	local statemin = `r(min)'
	local statemax = `r(max)'
	// "leave out" Missouri
	qui summ idd if state=="MISSOURI"
	local mizzou = `r(mean)'	// store the value of Missouri in this local	

// whether or not to "take out" non-near peak unemployment MO states
if "`comp_type'"=="all" {
	keep if peak_near_MO==1 & ui_debt>0
}
xtset idd yrqtr	// set as a time series			

// Store controls in a local
local control_vars home_own_rate est_job_gains est_job_losses share_manuf ///
	share_constr share_transport share_fire share_profbus share_educhealth ///
	share_leisure share_other share_govt
	
********************	
*****   newV/U
********************
***		reg on MO x Post, two way FE; cluster at the state level
	reghdfe log_newv_over_unemp MO_post `control_vars', a(yrqtr idd) vce(cluster idd)
	*qui reghdfe log_newv_over_unemp b204.Dyearq, absorb(idd yrqtr) cluster(idd) noconstant
		local b_VU_`sa_method'_`comp_type' = _b[MO_post]	// store beta coefficient
		local oneway_VU_`sa_method'_`comp_type' = _se[MO_post]	// store standard error
		local N_`sa_method'_`comp_type' = e(N)
		di `b_VU_`sa_method'_`comp_type''
		// format both the beta and SE
		local b_VU_`sa_method'_`comp_type' : di %4.3f `b_VU_`sa_method'_`comp_type''
		local oneway_VU_`sa_method'_`comp_type' : di %4.3f `oneway_VU_`sa_method'_`comp_type''
		local N_`sa_method'_`comp_type' : di %5.0fc `N_`sa_method'_`comp_type''			
			
	*****  reg newV/U on MO x Post, two way FE; cluster at the state & year-quarter level
	reghdfe log_newv_over_unemp MO_post `control_vars', a(yrqtr idd) vce(cluster yrqtr idd)
	*qui reghdfe log_newv_over_unemp b204.Dyearq, absorb(idd yrqtr) cluster(idd yrqtr) noconstant
		local twoway_VU_`sa_method'_`comp_type' = _se[MO_post]	// store standard error
		// format the SE
		local twoway_VU_`sa_method'_`comp_type' : di %4.3f `twoway_VU_`sa_method'_`comp_type''

********************	
*****   stable H/ new V
********************
***		reg on MO x Post, two way FE; cluster at the state level
	reghdfe log_newsh_over_newv MO_post `control_vars', a(yrqtr idd) vce(cluster idd)
	*qui reghdfe log_newv_over_unemp b204.Dyearq, absorb(idd yrqtr) cluster(idd) noconstant
		local b_HV_`sa_method'_`comp_type' = _b[MO_post]	// store beta coefficient
		local oneway_HV_`sa_method'_`comp_type' = _se[MO_post]	// store standard error
		// format both the beta and SE
		local b_HV_`sa_method'_`comp_type' : di %4.3f `b_HV_`sa_method'_`comp_type''
		local oneway_HV_`sa_method'_`comp_type' : di %4.3f `oneway_HV_`sa_method'_`comp_type''
			
	*****  reg newV/U on MO x Post, two way FE; cluster at the state & year-quarter level
	reghdfe log_newsh_over_newv MO_post `control_vars', a(yrqtr idd) vce(cluster yrqtr idd)
	*qui reghdfe log_newv_over_unemp b204.Dyearq, absorb(idd yrqtr) cluster(idd yrqtr) noconstant
		local twoway_HV_`sa_method'_`comp_type' = _se[MO_post]	// store standard error
		// format the SE
		local twoway_HV_`sa_method'_`comp_type' : di %4.3f `twoway_HV_`sa_method'_`comp_type''

****************************************************
**	Calculate Effect on Job Finding Rate, Steady-State Unemployment

	*Step 1: Obtain UE and EU flows that are adjusted for time aggregation bias
		use "${statedata}f_rate_state_cps_sa_shimeradj.dta", clear
		// only keep Missouri observations during relevant time span
			keep if statenameupper=="MISSOURI" & inrange(ym,ym(2011,1),ym(2011,3))
			tsset ym 	// set as time series(
		// extract the mean JFR in the quarter we want
			qui summ job_finding_rate
			local jfr_mean = `r(mean)'
			
		// same thing but for separation rate (Shimer adj EU rate)
		use "${statedata}s_rate_state_cps_sa_shimeradj.dta", clear
			// only keep Missouri observations during relevant time span
			keep if statenameupper=="MISSOURI" & inrange(ym,ym(2011,1),ym(2011,3))
			tsset ym 	// set as time series
		// extract the mean separation rate in the quarter we want
			summ separation_rate
			local sep_mean = `r(mean)'
			
		// create observed steady state unemployment rate
			local normal_ss_urate = 100*`sep_mean'/(`sep_mean'+ `jfr_mean')	
	
			// local for micro effect:
			local micro_`sa_method'_`comp_type' = `b_VU_`sa_method'_`comp_type'' + (1/(1-0.3))*`b_HV_`sa_method'_`comp_type''
			
			// local for theta (increase in market tightness):
			local theta_`sa_method'_`comp_type' = `b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type''
				
			// calclate job finding rate:
			local jfrate_`sa_method'_`comp_type' = `micro_`sa_method'_`comp_type'' + (0.3*(`theta_`sa_method'_`comp_type''))

			// calculate how much JFR Δ & new URate as result of policy:
			local ctrf_jfr_`sa_method'_`comp_type' = `jfr_mean'*exp((-1)*`jfrate_`sa_method'_`comp_type'')
			local ctrf_ss_urate_`sa_method'_`comp_type' = 100*`sep_mean'/(`sep_mean'+ `ctrf_jfr_`sa_method'_`comp_type'')
			// lastly, calculate the difference between the normal and ctrf URates (or JFR)
			local ss_urate_diff_`sa_method'_`comp_type' = `normal_ss_urate' - `ctrf_ss_urate_`sa_method'_`comp_type''			

			// format numbers	
			local jfrate_`sa_method'_`comp_type': di %4.3f `jfrate_`sa_method'_`comp_type''
			local ss_urate_diff_`sa_method'_`comp_type': di %3.2f `ss_urate_diff_`sa_method'_`comp_type''			
	}		


*** Write .tex table for main effects (all New Hires & New Vacancies)
texdoc init "${tables}panel_regressions_beta_wcontrols_bench.tex", replace force
tex \begin{tabular}{lrcccc} \toprule \toprule
tex     & &  (1) & (2) & (3) & (4) \\ \midrule 
tex    \multicolumn{2}{l}{A. \$Vacancies / Unemployment\$} & & & & \\
tex    & $\hat{\beta}_{MO\_post}$ & `b_VU_rat_all' & `b_VU_rat_restrict' & `b_VU_sep_all' & `b_VU_sep_restrict' \\
tex    & One-way clustered SE & (`oneway_VU_rat_all') & (`oneway_VU_rat_restrict') & (`oneway_VU_sep_all') & (`oneway_VU_sep_restrict')  \\
tex    & Two-way clustered SE & (`twoway_VU_rat_all') & (`twoway_VU_rat_restrict') & (`twoway_VU_sep_all') & (`twoway_VU_sep_restrict')  \\
tex    \addlinespace
tex    \multicolumn{2}{l}{B. \$Hires / Vacancies\$} & & & & \\
tex    & $\hat{\beta}_{MO\_post}$ & `b_HV_rat_all' & `b_HV_rat_restrict' & `b_HV_sep_all' & `b_HV_sep_restrict' \\
tex    & One-way clustered SE & (`oneway_HV_rat_all') & (`oneway_HV_rat_restrict') & (`oneway_HV_sep_all') & (`oneway_HV_sep_restrict') \\
tex    & Two-way clustered SE & (`twoway_HV_rat_all') & (`twoway_HV_rat_restrict') & (`twoway_HV_sep_all') & (`twoway_HV_sep_restrict') \\
tex    \addlinespace
tex    \addlinespace
tex	   \multicolumn{2}{l}{Implied Effects on \$f\$ and \$u_{ss}\$} & & & & \\
tex		& \$\Delta\$ log(\$f\$) & `jfrate_rat_all' & `jfrate_rat_restrict' & `jfrate_sep_all' & `jfrate_sep_restrict' \\
tex		& \$\Delta u_{ss}\$ (percentage points) & `ss_urate_diff_rat_all' & `ss_urate_diff_rat_restrict' & `ss_urate_diff_sep_all' & `ss_urate_diff_sep_restrict' \\
tex    \addlinespace
tex    \addlinespace
tex    \multicolumn{2}{l}{Include Control Vector} & \$\checkmark\$ & \$\checkmark\$ & \$\checkmark\$ & \$\checkmark\$ \\
tex    \multicolumn{2}{l}{Seasonal Adjustment as Ratios} & \$\checkmark\$ & \$\checkmark\$  & & \\
tex    \multicolumn{2}{l}{Seasonal Adjustment Separately} & & & \$\checkmark\$ & \$\checkmark\$ \\
tex    \multicolumn{2}{l}{Full Comparison Group} & & \$\checkmark\$ & & \$\checkmark\$ \\
tex \midrule
tex \$N\$ & & `N_rat_all' & `N_rat_restrict' & `N_sep_all' & `N_sep_restrict' \\ \bottomrule \bottomrule
tex \end{tabular}
texdoc close

end

********************************************************************************
** 		Table A.7: Decomposition with Control Vars
********************************************************************************
cap drop prog do_tablea7
prog define do_tablea7

*seasonal adjustment
local satype sep sep rat rat
* what type of comparison group
local compgroup restrict all restrict all

local timecount: word count(`compgroup')

forval k=1/`timecount' {
	local sa_method: word `k' of `satype'
	local comp_type: word `k' of `compgroup'
	
// read in diff file type depending on SA method
if "`sa_method'"=="sep" {
	local sa_longform "separate"
	use	"${statedata}synth_ready_quarterly.dta", clear
}
if "`sa_method'"=="rat" {
	local sa_longform "ratio"
	use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear
}

// drop states that also changed UI policies during this time or for which there isn't sufficient data
drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
	"MASSACHUSETTS","HAWAII","DISTRICT OF COLUMBIA")

keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
// merge "peak unemployment rate" info
merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
// whether or not to "take out" non-near peak unemployment MO states

merge m:1 state using "${statedata}ui_trust_fund.dta"

drop if _merge==2 // drops U.S. V.I.

replace ui_debt=0 if ui_debt==.
drop _merge

*******
*******
// IMPORTANT NOTE: To make the coding easier to adjust all = bench, i.e. restricted set of states == 1
//					thus, for compgroup=="restrict" is actually for all control units 
*******
*******
if "`comp_type'"=="all" {
	keep if peak_near_MO==1 & ui_debt>0
}
egen idd = group(state)
xtset idd yrqtr	// set as a time series			

* Store controls in a local
local control_vars home_own_rate est_job_gains est_job_losses share_manuf ///
	share_constr share_transport share_info share_fire share_profbus ///
	share_educhealth share_leisure share_other share_govt

qui reghdfe log_newv_over_unemp MO_post `control_vars', a(yrqtr idd) vce(cluster idd)
	local b_VU_`sa_method'_`comp_type' = _b[MO_post]	// store beta coefficient
qui reghdfe log_newh_over_newv MO_post `control_vars', a(yrqtr idd) vce(cluster idd)
	local b_HV_`sa_method'_`comp_type' = _b[MO_post]	// store beta coefficient


	foreach num in 50 55 60 { 
		// local for micro effect:
		local micro_`sa_method'_`comp_type'_wcontrols_`num' = `b_VU_`sa_method'_`comp_type'' + (1/(1-0.`num'))*`b_HV_`sa_method'_`comp_type''
			
		// local for theta (increase in market tightness)
		local theta_`sa_method'_`comp_type'_wcontrols_`num' = `b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type'_wcontrols_`num''
				
		// calclate job finding rate
		local jfrate_`sa_method'_`comp_type'_`num' = `micro_`sa_method'_`comp_type'_wcontrols_`num'' + (0.`num'*(`theta_`sa_method'_`comp_type'_wcontrols_`num''))
					
		// calculate share of change in JFR due to equilibrium
		if `jfrate_`sa_method'_`comp_type'_`num'' >= 0 {
			local equil_share_`sa_method'_`comp_type'_`num' = 100*((0.`num'*(`b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type'_wcontrols_`num''))/`jfrate_`sa_method'_`comp_type'_`num'')
		}
		if `jfrate_`sa_method'_`comp_type'_`num'' < 0 {
			local equil_share_`sa_method'_`comp_type'_`num' = -100*((0.`num'*(`b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type'_wcontrols_`num''))/`jfrate_`sa_method'_`comp_type'_`num'')	
		}	
		
		// format numbers
		local micro_`sa_method'_`comp_type'_wcontrols_`num': di %5.3f `micro_`sa_method'_`comp_type'_wcontrols_`num''
		local theta_`sa_method'_`comp_type'_wcontrols_`num': di %5.3f `theta_`sa_method'_`comp_type'_wcontrols_`num''
		local jfrate_`sa_method'_`comp_type'_`num': di %4.3f `jfrate_`sa_method'_`comp_type'_`num''
		local equil_share_`sa_method'_`comp_type'_`num': di %3.0f `equil_share_`sa_method'_`comp_type'_`num''
			
		di "Alpha = `num'"
		di "Search Effort: `micro_`sa_method'_`comp_type'_wcontrols_`num''"
		di "Theta: `theta_`sa_method'_`comp_type'_wcontrols_`num'' "
		di "Equil Share: `equil_share_`sa_method'_`comp_type'_`num''"
		
		***** Put micro, theta, Equil-Share in globals to be analzyed *****
		global macro_wctrl_`sa_method'_`comp_type'_`num' = `equil_share_`sa_method'_`comp_type'_`num''
		global theta_wctrl_`sa_method'_`comp_type'_`num' = `theta_`sa_method'_`comp_type'_wcontrols_`num''
		global micro_wctrl_`sa_method'_`comp_type'_`num' = `micro_`sa_method'_`comp_type'_wcontrols_`num''
		
		********** Put it into Tex **************************************	
		texdoc init "${tables}decomp_wcontrols_`sa_method'_`comp_type'_bench.tex", replace force
		tex  0.50  & `micro_`sa_method'_`comp_type'_wcontrols_50' & `theta_`sa_method'_`comp_type'_wcontrols_50' & `equil_share_`sa_method'_`comp_type'_50'\%  \\
		tex  0.55  & `micro_`sa_method'_`comp_type'_wcontrols_55' & `theta_`sa_method'_`comp_type'_wcontrols_55' & `equil_share_`sa_method'_`comp_type'_55'\%  \\
		tex  0.60  & `micro_`sa_method'_`comp_type'_wcontrols_60' & `theta_`sa_method'_`comp_type'_wcontrols_60' & `equil_share_`sa_method'_`comp_type'_60'\%  \\ 	
		texdoc close

	}	
	
}

end


/******************************************************************************/
** New Appendix Table A8: Decomposition Using All New Hires (not just Stable New Hires)
/******************************************************************************/
cap drop prog do_tablea8
prog define do_tablea8

*seasonal adjustment
local satype sep sep rat rat
* what type of comparison group
local compgroup all restrict all restrict

local timecount: word count(`compgroup')

forval k=1/`timecount' {
	local sa_method: word `k' of `satype'
	local comp_type: word `k' of `compgroup'

// read in diff file type depending on SA method
if "`sa_method'"=="sep" {
	local sa_longform "separate"
	use	"${statedata}synth_ready_quarterly.dta", clear
}
if "`sa_method'"=="rat" {
	local sa_longform "ratio"
	use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear
}

	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","HAWAII", "DISTRICT OF COLUMBIA")

	egen idd = group(state) 					// numeric value for each state
	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
		
	// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
		// Merge UI trust fund data	
merge m:1 state using "${statedata}ui_trust_fund.dta"

drop if _merge==2 // drops U.S. V.I.

replace ui_debt=0 if ui_debt==.
drop _merge

// whether or not to "take out" non-near peak unemployment MO states & insolvent
if "`comp_type'"=="all" {
	keep if peak_near_MO==1 & ui_debt>0
}
	xtset idd yrqtr								// set as a time series		

********************	
*****   newV/U
********************
***		reg on MO x Post, two way FE; cluster at the state level
	reghdfe log_newv_over_unemp MO_post, a(yrqtr idd) vce(cluster idd)
		local b_VU_`sa_method'_`comp_type' = _b[MO_post]	// store beta coefficient

********************	
*****   all H/ new V
********************
***		reg on MO x Post, two way FE; cluster at the state level
	reghdfe log_newh_over_newv MO_post, a(yrqtr idd) vce(cluster idd)
	*qui reghdfe log_newv_over_unemp b204.Dyearq, absorb(idd yrqtr) cluster(idd) noconstant
		local b_HV_`sa_method'_`comp_type' = _b[MO_post]	// store beta coefficient		
}

forval k=1/`timecount' {
	local sa_method: word `k' of `satype'
	local comp_type: word `k' of `compgroup'

		foreach num in 50 55 60 { 
			// local for micro effect:
			local micro_`sa_method'_`comp_type'_`num' = `b_VU_`sa_method'_`comp_type'' + (1/(1-0.`num'))*`b_HV_`sa_method'_`comp_type''
			
			// local for theta (increase in market tightness)
			local theta_`sa_method'_`comp_type'_`num' = `b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type'_`num''
				
			// calclate job finding rate
			local jfrate_`sa_method'_`comp_type'_`num' = `micro_`sa_method'_`comp_type'_`num'' + (0.`num'*(`theta_`sa_method'_`comp_type'_`num''))
					
			// calculate share of change in JFR due to equilibrium
			if `jfrate_`sa_method'_`comp_type'_`num'' >= 0 {
				local equil_share_`sa_method'_`comp_type'_`num' = 100*((0.`num'*(`b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type'_`num''))/`jfrate_`sa_method'_`comp_type'_`num'')
			}
			if `jfrate_`sa_method'_`comp_type'_`num'' < 0 {
				local equil_share_`sa_method'_`comp_type'_`num' = -100*((0.`num'*(`b_VU_`sa_method'_`comp_type''-`micro_`sa_method'_`comp_type'_`num''))/`jfrate_`sa_method'_`comp_type'_`num'')	
			}

			// format numbers
			local micro_`sa_method'_`comp_type'_`num': di %5.3f `micro_`sa_method'_`comp_type'_`num''
			local theta_`sa_method'_`comp_type'_`num': di %5.3f `theta_`sa_method'_`comp_type'_`num''
			local jfrate_`sa_method'_`comp_type'_`num': di %4.3f `jfrate_`sa_method'_`comp_type'_`num''
			local equil_share_`sa_method'_`comp_type'_`num': di %3.0f `equil_share_`sa_method'_`comp_type'_`num''
			
			di "Alpha = `num'"
			di "Search Effort: `micro_`sa_method'_`comp_type'_`num''"
			di "Theta: `theta_`sa_method'_`comp_type'_`num''"
			di "Equil Share: `equil_share_`sa_method'_`comp_type'_`num''"
			
			***** Put micro, theta, Equil-Share in globals to be analzyed *****
			global macro_`sa_method'_`comp_type'_`num' = `equil_share_`sa_method'_`comp_type'_`num''
			global theta_`sa_method'_`comp_type'_`num' = `theta_`sa_method'_`comp_type'_`num''
			global micro_`sa_method'_`comp_type'_`num' = `micro_`sa_method'_`comp_type'_`num''
			}
		********** Put it into Tex **************************************	
		texdoc init "${tables}decomp_VU_allnewHV_`sa_method'_`comp_type'_bench.tex", replace force
		tex  0.50  & `micro_`sa_method'_`comp_type'_50' & `theta_`sa_method'_`comp_type'_50' & `equil_share_`sa_method'_`comp_type'_50'\%  \\
		tex  0.55  & `micro_`sa_method'_`comp_type'_55' & `theta_`sa_method'_`comp_type'_55' & `equil_share_`sa_method'_`comp_type'_55'\%  \\
		tex  0.60  & `micro_`sa_method'_`comp_type'_60' & `theta_`sa_method'_`comp_type'_60' & `equil_share_`sa_method'_`comp_type'_60'\%  \\ 	
		texdoc close

		}	
	
	
end 


/******************************************************************************/
* 		Figure 1a: Dynamic Effect of UI Cut on Unemployment
*		 (and Figure A6: Dynamic Effect of UI Cut on Unemp Rate thru 2013Q4−2)
/******************************************************************************/
cap drop prog do_fig1a_fig3a_figA6
prog define do_fig1a_fig3a_figA6
use	"${statedata}synth_ready_quarterly.dta", clear

	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
	"HAWAII", "MASSACHUSETTS","DISTRICT OF COLUMBIA")
	
	// get the pre-treatment mean for Missouri
	egen idd = group(state)
	qui summ idd
	// put the min and max of state numbers into locals (necessary for permutation test)
	local statemin = `r(min)'
	local statemax = `r(max)'
	// "leave out" Missouri
	qui summ idd if state=="MISSOURI"
	local mizzou = `r(mean)'	// store the value of Missouri in this local		

	keep if inrange(yrqtr,${begyq},yq(2013,4))	// keep right data range
	xtset idd yrqtr	// set as a time series
	
	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

	// Merge UI trust fund data	
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.
	
	replace ui_debt=0 if ui_debt==.
	drop _merge

	// only restricted controls 
	// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen

	// benchmark control group
	eststo clear
	reghdfe urate b204.Dyearq if peak_near_MO==1 & ui_debt>0 & yrqtr <= ${endyq}, ///
		absorb(idd yrqtr) cluster(idd) noconstant
	eststo urate_bench
	
	coefplot urate_bench, vertical yline(0) ciopts(recast(rcap)) xlab(,angle(30) ///
	labsize(medlarge)) yti("Point Estimate", si(medlarge)) ///
	name(reg_urate_dynamic_bench, replace) baselevels scheme(s1color) ylab(, angle(0) ///
	labsize(medlarge)) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
		202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
		205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
		208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
		211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
		214.Dyearq = `"2013Q3"' 215.Dyearq = `" "') xline(5.5, lpattern(dashed) lc(gray))
	gr export "${figures}reg_urate_dynamic_bench.eps", replace as(eps)
	
	
	// all control units
	eststo clear
	reghdfe urate b204.Dyearq if yrqtr <= ${endyq}, ///
		absorb(idd yrqtr) cluster(idd) noconstant
	eststo urate_all
	
	coefplot urate_all, vertical yline(0) ciopts(recast(rcap)) xlab(,angle(30) ///
	labsize(medlarge)) yti("Point Estimate", si(medlarge)) ///
	name(reg_urate_dynamic, replace) baselevels scheme(s1color) ylab(, angle(0) ///
	labsize(medlarge)) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
		202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
		205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
		208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
		211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
		214.Dyearq = `"2013Q3"' 215.Dyearq = `" "') xline(5.5, lpattern(dashed) lc(gray))
	gr export "${figures}reg_urate_dynamic.eps", replace as(eps)
	
	// all states vs. benchmark 
	reghdfe urate b204.Dyearq, absorb(idd yrqtr) cluster(idd) noconstant
	eststo urate_extended

	reghdfe urate b204.Dyearq if peak_near_MO==1 & ui_debt>0, absorb(idd yrqtr) ///
		cluster(idd) noconstant
	eststo urate_extended_bench

	coefplot urate_extended urate_extended_bench, vertical yline(0) ///
	ciopts(recast(rcap)) xlab(,angle(30) labsize(medlarge)) yti("Point Estimate", ///
	si(medlarge)) name(reg_urate_dynamic_bench_and_all, replace) baselevels scheme(s1color) ///
	ylab(, angle(0) labsize(medlarge)) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
		202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
		205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
		208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
		211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
		214.Dyearq = `"2013Q3"' 215.Dyearq = `" "') xline(5.5, lpattern(dashed) lc(gray)) ///
	legend(label(2 "All Control Units") label(4 "Benchmark") ///
		ring(0) position(1) bmargin(small) colgap(*0.55))
	gr export "${figures}reg_urate_dynamic_bench_and_all.eps", replace as(eps)
	
end


/******************************************************************************/
*  		Figure 1b: Dynamic Effect of UI Cut on Log(V)
*  also Fig A11: Log(H); Fig A12: Log(LF), ratios, A13-16: Raw Time Series
/******************************************************************************/
cap drop prog constituent_bench
prog define constituent_bench
	use	"${statedata}synth_ready_quarterly.dta", clear
	
	// drop states that also changed UI policies during this time or not sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"HAWAII", "MASSACHUSETTS","DISTRICT OF COLUMBIA")
	
	// get the pre-treatment mean for Missouri
	egen idd = group(state)

	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	xtset idd yrqtr	// set as a time series	

	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.	
	replace ui_debt=0 if ui_debt==.
	drop _merge
	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

	eststo clear
		
	reghdfe log_newv b204.Dyearq if peak_near_MO==1 & ui_debt>0,  absorb(idd yrqtr) cluster(idd) nocon
		coefplot, vertical yline(0) ciopts(recast(rcap)) ylab(, labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("Point Estimate", si(medlarge)) ///
			name(V_restrictcontrol_bench, replace) ///
			baselevels scheme(s1color) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
			202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
			205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
			208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
			211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
			214.Dyearq = `"2013Q3"' 215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray))	
		gr export "${figures}V_beg2010Q1_end2012Q3_restrictcontrol_bench.eps", as(eps) replace

	eststo clear
		
	reghdfe log_newv b204.Dyearq,  absorb(idd yrqtr) cluster(idd) nocon
		coefplot, vertical yline(0) ciopts(recast(rcap)) ylab(, labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("Point Estimate", si(medlarge)) ///
			name(V_all, replace) ///
			baselevels scheme(s1color) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
			202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
			205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
			208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
			211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
			214.Dyearq = `"2013Q3"' 215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray))	
		gr export "${figures}V_beg2010Q1_end2012Q3.eps", as(eps) replace
		
	************
	**  Fig A11: H alone
	************
		// back out new-stable hires since you don't have it in the dataset (H= H/V * V)
		gen newsh = newsh_over_newv * total_newvacancies_state
		gen log_newsh = log(newsh)
		br newsh newsh_over_newv total_newvacancies_state log_newsh_over_newv
		keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	
		eststo clear
	reghdfe log_newsh b204.Dyearq, absorb(idd yrqtr) cluster(idd) noconstant
	eststo hires_all
	reghdfe log_newsh b204.Dyearq if peak_near_MO==1 & ui_debt>0, absorb(idd yrqtr) cluster(idd ) noconstant
	eststo hires_restrict
		coefplot hires_all hires_restrict, vertical yline(0) ciopts(recast(rcap)) ylab(, labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("log(H)", si(medlarge)) ///
			name(newH_allcomp, replace) ///
			baselevels scheme(s1color) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
			202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
			205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
			208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
			211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
			214.Dyearq = `"2013Q3"' 215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray)) ///
		legend(label(2 "All Control Units") label(4 "Benchmark") ///
		ring(0) position(1) bmargin(small) colgap(*0.55))
		gr export "${figures}sH_all_restrict_beg2010Q1_end2012Q3_bench.eps", as(eps) replace
	
	************
	**  Effect on size of LF (Fig A12)
	************
	eststo clear
	gen log_LF = log(labor_force)
	reghdfe log_LF b204.Dyearq, absorb(idd yrqtr) cluster(idd ) noconstant
		eststo LF_all
	reghdfe log_LF b204.Dyearq if peak_near_MO==1 & ui_debt>0, absorb(idd yrqtr) cluster(idd) noconstant
		eststo LF_restrict
	coefplot LF_all LF_restrict, vertical yline(0) ciopts(recast(rcap)) ylab(, labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("log(Labor Force)", si(medlarge)) ///
			name(LF, replace) ///
			baselevels scheme(s1color) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
			202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
			205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
			208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
			211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
			214.Dyearq = `"2013Q3"' 215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray)) ///
		legend(label(2 "All Control Units") label(4 "Benchmark") ///
		ring(0) position(1) bmargin(small) colgap(*0.55))	
	gr export "${figures}LF_2010Q1_2012Q3_bench.eps", as(eps) replace

	************
	**  Effect on employment (Fig A13)
	************
	// create employment
	gen emp = labor_force - unemp 
	gen log_emp = log(emp)
	reghdfe log_emp b204.Dyearq, absorb(idd yrqtr) cluster(idd) noconstant
		eststo emp_all
	reghdfe log_emp b204.Dyearq if peak_near_MO==1 & ui_debt>0, absorb(idd yrqtr) cluster(idd) noconstant
		eststo emp_restrict
	coefplot emp_all emp_restrict, vertical yline(0) ciopts(recast(rcap)) ylab(, labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("log(Employment)", si(medlarge)) ///
			name(emp, replace) ///
			baselevels scheme(s1color) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
			202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
			205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
			208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
			211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
			214.Dyearq = `"2013Q3"' 215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray)) ///
		legend(label(2 "All Control Units") label(4 "Benchmark") ///
		ring(0) position(5) bmargin(small) colgap(*0.55))	
	gr export "${figures}emp_2010Q1_2012Q3_bench.eps", as(eps) replace

	************
	**  EVOLUTION OF RAW TIME SERIES (Fig A14)
	************
	// we use "hirns" for new stable hires 
	
	keep if abbv=="MO"
	// step 1: normalize to 2010Q1 	
	gen newsh_2010Q1_tmp = hirns if year==2010 & qtr==1	// H
	gen newv_2010Q1_tmp = total_newvacancies_state if year==2010 & qtr==1	// V 
	gen unemp_2010Q1_tmp = unemp if year==2010 & qtr==1 	// U 
	egen newsh_2010Q1 = max(newsh_2010Q1_tmp)
	egen newv_2010Q1 = max(newv_2010Q1_tmp)
	egen unemp_2010Q1 = max(unemp_2010Q1_tmp)	
	
	// step 2: divide by 2010Q1 level
	gen norm_newsh = hirns/newsh_2010Q1
	gen norm_newv = total_newvacancies_state / newv_2010Q1
	gen norm_unemp = unemp / unemp_2010Q1
	
	tsset yq 
	
	**** Figure A14: Evolution of Key Labor Market Variables in Missouri
	tw (connected norm_newsh yq) (connected norm_newv yq) (connected norm_unemp yq), ///
	scheme(s1color) ylab(, angle(0) labsize(medlarge)) yline(1) ///
	yti("Level Normalized to 2010Q1", si(medlarge)) xlab(,angle(30) labsize(medlarge)) ///
	legend(r(3) label(1 "Hires") label(2 "Vacancies") label(3 "Unemployment") ///
	ring(0) position(8) bmargin(small) symx(*0.6)) xti("")
	
	gr export "${figures}H_V_U_normalized_2010Q1.eps", as(eps) replace

	// step 1: normalize to 2010Q1 
	gen VU_2010Q1_tmp = total_newvacancies_state/unemp if year==2010 & qtr==1	// V/U
	gen HV_2010Q1_tmp = hirns/total_newvacancies_state if year==2010 & qtr==1	// H/V 
	egen VU_2010Q1 = max(VU_2010Q1_tmp)
	egen HV_2010Q1 = max(HV_2010Q1_tmp)
	
	// step 2: divide by 2010Q1 level
	gen norm_VU = (total_newvacancies_state/unemp) / VU_2010Q1
	gen norm_HV = (hirns/total_newvacancies_state) / HV_2010Q1
	
	tsset yq 
	tw (connected norm_VU yq) (connected norm_HV yq), ///
	scheme(s1color) ylab(, angle(0) labsize(medlarge)) yline(1) ///
	yti("Level Normalized to 2010Q1", si(medlarge)) xlab(,angle(30) labsize(medlarge)) ///
	legend(r(3) label(1 "V/U") label(2 "H/V") ring(0) position(11) bmargin(small) symx(*0.6)) ///
	xti("") name(VU_HV_norm, replace)
	
	gr export "${figures}VU_HV_normalized_2010Q1.eps", as(eps) replace
	
************
**  V/L (Fig A15)
************
	cap gen V_over_L = total_newvacancies_state/labor_force	  // Vac / LF 
	cap gen V_over_L_2010Q1_tmp = V_over_L if year==2010 & qtr==1
	cap egen V_over_L_2010Q1=max(V_over_L_2010Q1_tmp)		// normalize to 2010Q1 level
	cap gen norm_VL = V_over_L/V_over_L_2010Q1
	
	tsset yq 
	tw (connected norm_VL yq), ///
	scheme(s1color) ylab(, angle(0) labsize(medlarge)) yline(1) name(VL, replace) ///
	yti("Vacancies/Labor Force: Normalized to 2010Q1", si(medlarge)) xlab(,angle(30) labsize(medlarge)) ///
	xti("")
	
	gr export "${figures}VL_normalized_Missouri.eps", as(eps) replace
	
	
************
**  H/E  (Fig A16)
************
	cap gen H_over_E = hirns/emp	  // Hires / Emp 
	gen H_over_E_2010Q1_tmp = H_over_E if year==2010 & qtr==1
	cap egen H_over_E_2010Q1=max(H_over_E_2010Q1_tmp)		// normalize to 2010Q1 level
	cap gen norm_HE = H_over_E/H_over_E_2010Q1
	tsset yq 
	tw (connected norm_HE yq), ///
	scheme(s1color) ylab(, angle(0) labsize(medlarge)) yline(1) name(HE, replace) ///
	yti("Hires/Employment: Normalized to 2010Q1", si(medlarge)) xlab(,angle(30) labsize(medlarge)) ///
	xti("")
	
	gr export "${figures}HE_normalized_Missouri.eps", as(eps) replace
end


/******************************************************************************/
*  		Figure 2: Dynamic Effect of UI Cut on Missouri: Benchmark
/******************************************************************************/
cap drop prog fig_dyn_effect_bench
prog define fig_dyn_effect_bench
**==================================================================**

	use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear

	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","HAWAII","DISTRICT OF COLUMBIA")

	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
		
	// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
		// Merge UI trust fund data	
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.
	
	replace ui_debt=0 if ui_debt==.
	drop _merge

	keep if peak_near_MO==1	& ui_debt>0  // restrict to "peak near MO" & UI trust fund debt
	
	// get the pre-treatment mean for Missouri
	egen idd = group(state)	
	xtset idd yrqtr	// set as a time series			
	
	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

	eststo clear
	foreach var in log_newv_over_unemp log_newsh_over_newv {	// loop over V/U and H/V
		// need abbreviations associated with each variable for shortening of local
		if "`var'"=="log_newv_over_unemp"{
			local tag "VU"
			local ang = 0
		}
		if "`var'"=="log_newsh_over_newv"{
			local tag "sHV"
			local ang = 90
		}
		*****   reg Y on MO x Post, two way FE; cluster at the state level
		reghdfe `var' b204.Dyearq, absorb(idd yrqtr) cluster(idd) noconstant
		coefplot, vertical yline(0) ciopts(recast(rcap)) ylab(, angle(`ang') labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("Point Estimate", si(medlarge)) ///
		name(`tag'_SA_restricted_control, replace) baselevels scheme(s1color) ///
		coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' 202.Dyearq = `"2010Q3"' ///
		203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' 205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' ///
		207.Dyearq = `" "' 208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
		211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' 214.Dyearq = `"2013Q3"' ///
		215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray))
		
		gr export "${figures}`tag'_beg2010Q1_end2012Q3_SArat_bench.eps", as(eps) replace
	}
	
end

********************************************************************************
** 		Figure A.7: Dynamic Effects of UI Cut with Control Vars
********************************************************************************

cap drop prog fig_dyn_wcontrolvars_bench
prog define fig_dyn_wcontrolvars_bench
**==================================================================**
**==================================================================**
**==================================================================**

*outcome variables
local sa_vars log_newsh_over_newv log_newv_over_unemp

*seasonal adjustment
local satype rat

local timecount: word count(`satype')
**==================================================================**
**==================================================================**
**==================================================================**

forval k=1/`timecount' {
local sa_method: word `k' of `satype'

// read in diff file type depending on SA method
if "`sa_method'"=="rat" {
	local sa_longform "ratio"
	use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear
}
	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA", "HAWAII", ///
		"GEORGIA","MASSACHUSETTS","DISTRICT OF COLUMBIA")
	
	// get the pre-treatment mean for Missouri
	egen idd = group(state)
	qui summ idd
	// put the min and max of state numbers into locals (necessary for permutation test)
	local statemin = `r(min)'
	local statemax = `r(max)'
	// "leave out" Missouri
	qui summ idd if state=="MISSOURI"
	local mizzou = `r(mean)'	// store the value of Missouri in this local		
	
	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	xtset idd yrqtr	// set as a time series			
	
	// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
		// Merge UI trust fund data	
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.
	
	replace ui_debt=0 if ui_debt==.
	drop _merge

	// keep only those that are benchmarks near MO unemp peak and UI trust debt
	keep if peak_near_MO==1	& ui_debt>0 
	
	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

	* Store controls in a local
	local control_vars home_own_rate est_job_gains est_job_losses share_manuf ///
		share_constr share_transport share_info share_fire share_profbus ///
		share_educhealth share_leisure share_other share_govt
	
	eststo clear
	foreach var in `sa_vars' {	// loop over V/U and H/V
		// need abbreviations associated with each variable for shortening of local
		if "`var'"=="log_newv_over_unemp"{
			local tag "VU"
			local clockpos=11

		}
		if "`var'"=="log_newsh_over_newv"{
			local tag "sHV"
			local clockpos=7
		}
		*****   reg Y on MO x Post, two way FE; cluster at the state level
		di "`var' & BegYr: `thebegyr' BegQtr: `thebegqtr' & SA: `sa_method'"
		reghdfe `var' b204.Dyearq, absorb(idd yrqtr) cluster(idd ) noconstant
		eststo no_controls
		
		reghdfe `var' b204.Dyearq `control_vars', absorb(idd yrqtr) cluster(idd ) noconstant
		eststo controls

		*matrix list e(b) 
		coefplot no_controls controls, vertical yline(0) ciopts(recast(rcap)) ylab(, labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("Point Estimate", si(medlarge)) ///
		name(`var'_SA`sa_method', replace) ///
		baselevels scheme(s1color) coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' ///
		202.Dyearq = `"2010Q3"' 203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' ///
		205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' ///
		208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
		211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' ///
		214.Dyearq = `"2013Q3"' 215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray)) ///
		keep(*.Dyearq) legend(label(2 "No Controls")label(4 "Controls") pos(`clockpos') ring(0) colg(2))
		
		gr export "${figures}`tag'_beg2010Q1_end2012Q3_SA`sa_method'_controls_or_not_bench.eps", as(eps) replace
	}
}
end
 
********************************************************************************
** 		Figure 4 & 5: Histogram of Estimates
********************************************************************************
cap drop prog histo_decomp_est
prog define histo_decomp_est

// do the decompositions
do_tables2and3
clear
set obs 1

* Create variables with their initial values
gen sa_method = "rat"
gen alpha = "0.50"
gen comp_type = "all"

* Expand the dataset for the combinations
expand 12 		// used to be 24

* Assign values to sa_method
replace sa_method = "sep" in 7/12	

* Assign values to alpha
replace alpha = "0.55" in 3/4
replace alpha = "0.55" in 9/10
replace alpha = "0.60" in 5/6
replace alpha = "0.60" in 11/12

* Assign values to comp_type
replace comp_type = "restrict" in 2
replace comp_type = "restrict" in 4
replace comp_type = "restrict" in 6
replace comp_type = "restrict" in 8
replace comp_type = "restrict" in 10
replace comp_type = "restrict" in 12

gen micro =.
gen macro =.
gen theta =.
foreach meas in macro theta micro {
	foreach method in sep rat {
		foreach ctype in all restrict {
			foreach a in 50 55 60 {
				local alpha_val = "0." + "`a'"
				replace `meas' = ${`meas'_`method'_`ctype'_`a'} if alpha=="`alpha_val'" & ///
					sa_method=="`method'" & comp_type=="`ctype'"
			}
		}
	}
}
gen controls = "no"
save "${statedata}histograms_mainpaper.dta", replace

hist macro, w(6) xline(58) start(20) xti("Share Attributable to Macro Effects (%)", si(large)) ///
	ylab(0(5)20, angle(0) labs(medlarge)) scheme(s1color) xlab(, labs(medlarge)) percent ///
	graphregion(color(white)) bcolor(ltblue) blcolor(gs4) name(macro_share, replace) ///
	yti("Percent", si(medlarge))
gr export "${figures}hist_macroshare_mainpaper.eps", as(eps) replace

hist micro, w(.005) start(.02) xline(.05) xti("Change in Search Effort (log points)", si(large)) ///
	ylab(0(5)25, angle(0) labs(medlarge)) scheme(s1color) xlab(, labs(medlarge)) percent ///
	graphregion(color(white)) bcolor(ltblue) blcolor(gs4) name(micro_share, replace) ///
	yti("Percent", si(medlarge))
gr export "${figures}hist_searcheffort_mainpaper.eps", as(eps) replace

hist theta, w(.01) start(.02) xline(.124) ylab(0(5)25, angle(0) labs(medlarge)) scheme(s1color)  ///
	xti("Change in Market Tightness (log points)", si(large)) percent ///
	xlab(, labs(medlarge)) graphregion(color(white)) bcolor(ltblue) blcolor(gs4) ///
	name(theta_hist, replace) yti("Percent", si(medlarge))
gr export "${figures}hist_theta_mainpaper.eps", as(eps) replace


******
** Political controls (with similar unemployment rate peaks)
do_tables6and7

clear
set obs 1

* Create variables with their initial values
gen sa_method = "rat"
gen alpha = "0.50"
gen comp_type = 2

* Expand the dataset for the combinations
expand 12 		// used to be 24

* Assign values to sa_method
replace sa_method = "sep" in 7/12	

* Assign values to alpha
replace alpha = "0.55" in 3/4
replace alpha = "0.55" in 9/10
replace alpha = "0.60" in 5/6
replace alpha = "0.60" in 11/12

* Assign values to comp_type
replace comp_type = 3 in 2
replace comp_type = 3 in 4
replace comp_type = 3 in 6
replace comp_type = 3 in 8
replace comp_type = 3 in 10
replace comp_type = 3 in 12

gen micro =.
gen macro =.
gen theta =.
foreach meas in macro theta micro {
	foreach method in rat sep {
		forval ctype=2/3{
			foreach a in 50 55 60 {
				local alpha_val = "0." + "`a'"
				di "${`meas'_`method'_comp`ctype'_`a'}"
				replace `meas' = ${`meas'_`method'_comp`ctype'_`a'} ///
					if alpha=="`alpha_val'" & sa_method=="`method'" & comp_type==`ctype'
			}
		}
	}
}

ren comp_type comp_type2
gen comp_type = "GOP legislature" if comp_type2==1
replace comp_type = "Obama voteshare" if comp_type2==2
drop comp_type2
gen controls = "no"
save "${statedata}histograms_politics.dta", replace
	
	
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// now do it for the appendix results 
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
	
	
	
******
******
** Surrounding States
do_tablea4_figa5
******
******

clear
set obs 1

* Create variables with their initial values
gen sa_method = "rat"
gen alpha = "0.50"
gen comp_type = "surrounding states"
gen controls = "no"

* Expand the dataset for the combinations
expand 6		// used to be 24

* Assign values to sa_method
replace sa_method = "sep" in 4/6	

* Assign values to alpha
replace alpha = "0.55" in 2
replace alpha = "0.55" in 5
replace alpha = "0.60" in 3
replace alpha = "0.60" in 6

gen micro =.
gen macro =.
gen theta =.

foreach meas in macro theta micro {
	foreach method in sep rat {
		foreach a in 50 55 60 {
			local alpha_val = "0." + "`a'"
			replace `meas' = ${`meas'_`method'_`a'} if alpha=="`alpha_val'" & ///
				sa_method=="`method'"
		}
	}
}


save "${statedata}histograms_surroundstates.dta", replace

******
******
** With Covariates
do_tablea9
******
******

clear
set obs 1

* Create variables with their initial values
gen sa_method = "rat"
gen alpha = "0.50"
gen comp_type = "all"
gen controls = "yes"

* Expand the dataset for the combinations
expand 12 		// used to be 24

* Assign values to sa_method
replace sa_method = "sep" in 7/12	

* Assign values to alpha
replace alpha = "0.55" in 3/4
replace alpha = "0.55" in 9/10
replace alpha = "0.60" in 5/6
replace alpha = "0.60" in 11/12

* Assign values to comp_type
replace comp_type = "restrict" in 2
replace comp_type = "restrict" in 4
replace comp_type = "restrict" in 6
replace comp_type = "restrict" in 8
replace comp_type = "restrict" in 10
replace comp_type = "restrict" in 12

gen micro =.
gen macro =.
gen theta =.
foreach meas in theta micro macro {
	foreach method in sep rat {
		foreach ctype in all restrict {
			foreach a in 50 55 60 {
				local alpha_val = "0." + "`a'"
				replace `meas' = ${`meas'_wctrl_`method'_`ctype'_`a'} ///
					if alpha=="`alpha_val'" & sa_method=="`method'" & comp_type=="`ctype'"
			}
		}
	}
}

save "${statedata}histograms_with_controls.dta", replace
	

		
// append estimates together, make histograms 
use "${statedata}histograms_mainpaper.dta", clear
desc, s
append using "${statedata}histograms_surroundstates.dta"
append using "${statedata}histograms_politics.dta"
append using "${statedata}histograms_with_controls.dta"
		
	
// Equilibrium (Macro Effects) Share
hist macro, w(5) xline(58) start(15) xti("Share Attributable to Macro Effects (%)", si(large)) ///
	ylab(0(5)20, angle(0) labs(medlarge)) scheme(s1color) xlab(, labs(medlarge)) percent ///
	graphregion(color(white)) bcolor(ltblue) blcolor(gs4) name(macro_share, replace) ///
	yti("Percent", si(medlarge))
gr export "${figures}hist_macroshare_allspecifications.eps", as(eps) replace
	
// Search Effects
hist micro, w(.01) start(.01) xline(.05) xti("Change in Search Effort (log points)", si(large)) ///
	ylab(0(5)30, angle(0) labs(medlarge)) scheme(s1color) xlab(, labs(medlarge)) percent ///
	graphregion(color(white)) bcolor(ltblue) blcolor(gs4) name(micro_share, replace) ///
	yti("Percent", si(medlarge))
gr export "${figures}hist_searcheffort_allspecifications.eps", as(eps) replace

// Tightness Effects
hist theta, w(.015) start(.025) xline(.124) ylab(0(10)50, angle(0) labs(medlarge)) scheme(s1color)  ///
	xti("Change in Market Tightness (log points)", si(large)) percent ///
	xlab(, labs(medlarge)) graphregion(color(white)) bcolor(ltblue) blcolor(gs4) ///
	name(theta_hist, replace) yti("Percent", si(medlarge))
gr export "${figures}hist_theta_allspecifications.eps", as(eps) replace


end


/******************************************************************************/
* 	Figure A.2 & A.3: Dynamic Effect of UI Cut on Missouri: Restrict Control
/******************************************************************************/
cap drop prog fig_dyn_effect_restrictcomp
prog define fig_dyn_effect_restrictcomp
**==================================================================**
**==================================================================**
**==================================================================**

	use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear

	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","HAWAII","DISTRICT OF COLUMBIA")

	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
		
	// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
	keep if peak_near_MO==1	  // restrict to "peak near MO"
	
	// get the pre-treatment mean for Missouri
	egen idd = group(state)	
	xtset idd yrqtr	// set as a time series			
	
	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

	eststo clear
	foreach var in log_newv_over_unemp log_newsh_over_newv {	// loop over V/U and H/V
		// need abbreviations associated with each variable for shortening of local
		if "`var'"=="log_newv_over_unemp"{
			local tag "VU"
		}
		if "`var'"=="log_newsh_over_newv"{
			local tag "sHV"
		}
		*****   reg Y on MO x Post, two way FE; cluster at the state level
		reghdfe `var' b204.Dyearq, absorb(idd yrqtr) cluster(idd) noconstant
		coefplot, vertical yline(0) ciopts(recast(rcap)) ylab(, angle(0) labsize(medlarge)) ///
		xlab(,angle(30) labsize(medlarge)) yti("Point Estimate", si(medlarge)) ///
		name(`tag'_SA_restricted_control, replace) baselevels scheme(s1color) ///
		coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' 202.Dyearq = `"2010Q3"' ///
		203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' 205.Dyearq = `" "' 206.Dyearq = `"2011Q3"' ///
		207.Dyearq = `" "' 208.Dyearq = `"2012Q1"' 209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' ///
		211.Dyearq = `" "' 212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' 214.Dyearq = `"2013Q3"' ///
		215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray))
		
		gr export "${figures}`tag'_beg2010Q1_end2012Q3_SArat_restrictcontrol.eps", as(eps) replace
	}

end


/******************************************************************************/
** Appendix Figure A.8: Log(V/U). Alt Measure & Seasonality
/******************************************************************************/
cap drop prog figure_alt_VU_allvac_bench	
prog define figure_alt_VU_allvac_bench

use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear
	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","HAWAII", "DISTRICT OF COLUMBIA")

	egen idd = group(state) 					// numeric value for each state
	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	
			// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
		// Merge UI trust fund data	
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.
	
	replace ui_debt=0 if ui_debt==.
	drop _merge

	keep if peak_near_MO==1	& ui_debt>0  // restrict to "peak near MO"
	
	xtset idd yrqtr								// set as a time series		

	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

	eststo clear
	reghdfe log_newv_over_unemp b204.Dyearq, absorb(idd yrqtr) cluster(idd ) noconstant
		eststo baseline_vu
	reghdfe log_v_over_unemp b204.Dyearq, absorb(idd yrqtr) cluster(idd ) noconstant
		eststo all_vu

use	"${statedata}synth_ready_quarterly.dta", clear
	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","HAWAII", "DISTRICT OF COLUMBIA")

	egen idd = group(state) 					// numeric value for each state
	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	
		// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
		// Merge UI trust fund data	
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.
	
	replace ui_debt=0 if ui_debt==.
	drop _merge
	
	keep if peak_near_MO==1	& ui_debt>0  // restrict to "peak near MO"
	
	xtset idd yrqtr								// set as a time series		

	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

	reghdfe log_newv_over_unemp b204.Dyearq, absorb(idd yrqtr) cluster(idd ) noconstant
		eststo baseline_vu_sep
	reghdfe log_v_over_unemp b204.Dyearq, absorb(idd yrqtr) cluster(idd ) noconstant
		eststo all_vu_sep
		
* plot estimates from baseline & all vacancies against each other
coefplot baseline_vu all_vu baseline_vu_sep all_vu_sep, vertical yline(0) ///
	ciopts(recast(rcap)) ylab(, angle(0) labsize(medlarge)) ///
	xlab(,angle(30) labsize(medlarge)) yti("Point Estimate", si(medlarge)) ///
	name(newVU_allVU_SArat, replace) baselevels scheme(s1color) ///
	coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' 202.Dyearq = `"2010Q3"' ///
	203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' 205.Dyearq = `" "' ///
	206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' 208.Dyearq = `"2012Q1"' ///
	209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' 211.Dyearq = `" "' ///
	212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' 214.Dyearq = `"2013Q3"' ///
	215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray)) legend(r(2) ///
	label(2 "New Vacancies; SA Ratio (baseline)") label(4 "All Vacancies; SA Ratio") ///
	label(6 "New Vacancies; SA Separately") label(8 "All Vacancies; SA Separately"))
	
gr export "${figures}VU_new_vs_allV_beg2010Q1_end2012Q3_bench.eps", as(eps) replace

end


/******************************************************************************/
** Appendix Figure A.9: Log(H/V)  Alt Measure & Seasonality
/******************************************************************************/
cap drop prog figure_alt_HV_bench
prog define figure_alt_HV_bench

use	"${statedata}synth_ready_quarterly_SAtightness.dta", clear
	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","HAWAII", "DISTRICT OF COLUMBIA")

	egen idd = group(state) 					// numeric value for each state
	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range

	// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
		// Merge UI trust fund data	
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.
	
	replace ui_debt=0 if ui_debt==.
	drop _merge

	
	keep if peak_near_MO==1	& ui_debt>0  // restrict to "peak near MO"

	xtset idd yrqtr								// set as a time series		

	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

	eststo clear
	reghdfe log_newsh_over_newv b204.Dyearq, absorb(idd yrqtr) cluster(idd ) noconstant
		eststo baseline_hv_rat
	reghdfe log_newh_over_newv b204.Dyearq, absorb(idd yrqtr ) cluster(idd ) noconstant
		eststo all_hv_rat
	
use	"${statedata}synth_ready_quarterly.dta", clear
	// drop states that also changed UI policies during this time or for which there isn't sufficient data
	drop if inlist(state,"FLORIDA","ARKANSAS","MICHIGAN","SOUTH CAROLINA","GEORGIA", ///
		"MASSACHUSETTS","HAWAII", "DISTRICT OF COLUMBIA")

	egen idd = group(state) 					// numeric value for each state
	keep if inrange(yrqtr,${begyq},${endyq})	// keep right data range
	
		// merge "peak unemployment rate" info
	merge m:1 abbv using "${statedata}peak_UR_dates_44states.dta", nogen
		// Merge UI trust fund data	
	merge m:1 state using "${statedata}ui_trust_fund.dta"

	drop if _merge==2 // drops U.S. V.I.
	
	replace ui_debt=0 if ui_debt==.
	drop _merge

	
	keep if peak_near_MO==1	& ui_debt>0  // restrict to "peak near MO"
	
	xtset idd yrqtr								// set as a time series		

	* Create a treatment dummy
	gen D = (state=="MISSOURI")
	gen Dyearq = cond(D, yq, yq(2011,1))	// = year if D=1, = 2013 if D=0

	reghdfe log_newsh_over_newv b204.Dyearq, absorb(idd yrqtr) cluster(idd ) noconstant
		eststo baseline_hv_sep
	reghdfe log_newh_over_newv b204.Dyearq, absorb(idd yrqtr) cluster(idd ) noconstant
		eststo all_hv_sep	

* plot estimates from baseline & all vacancies against each other
coefplot baseline_hv_rat all_hv_rat baseline_hv_sep all_hv_sep, vertical yline(0) ///
	ciopts(recast(rcap)) ylab(, angle(0) labsize(medlarge)) ///
	xlab(,angle(30) labsize(medlarge)) yti("Point Estimate", si(medlarge)) ///
	name(HV_stableornot_SArat, replace) baselevels scheme(s1color) ///
	coeflabels(200.Dyearq = `"2010Q1"' 201.Dyearq = `" "' 202.Dyearq = `"2010Q3"' ///
	203.Dyearq = `" "' 204.Dyearq = `"2011Q1"' 205.Dyearq = `" "' ///
	206.Dyearq = `"2011Q3"' 207.Dyearq = `" "' 208.Dyearq = `"2012Q1"' ///
	209.Dyearq = `" "' 210.Dyearq = `"2012Q3"' 211.Dyearq = `" "' ///
	212.Dyearq = `"2013Q1"' 213.Dyearq = `" "' 214.Dyearq = `"2013Q3"' ///
	215.Dyearq = `" "')	xline(5.5, lpattern(dashed) lc(gray)) legend(r(2) span ///
	label(2 "New Stable Hires; SA Ratio (baseline)")label(4 "All New Hires; SA Ratio") ///
	label(6 "New Stable Hires; SA Separately") label(8 "All New Hires; SA Separately") colg(3))
	
gr export "${figures}HV_stable_vs_allH_beg2010Q1_end2012Q3_bench.eps", as(eps) replace

end


/******************************************************************************/
** Appendix Figure A.10: Vacancies-Unemployment vs. Hires, All States, 2006Q3-2012Q3
/******************************************************************************/
cap drop prog figure_VU_vs_H
prog define figure_VU_vs_H

	use"${statedata}synth_ready_quarterly.dta", clear
	collapse (mean) unemp log_newv total_newvacancies_state hirn [aw=population], by(yrqtr)
	gen log_vu = log(total_newvacancies_state/unemp)	// create log V/U
	gen log_h = log(hirn)	// create log hires 
	gen log_u = log(unemp)
	gen log_v = log(total_newvacancies_state)

	// create a time label
	gen YQ_label = ""
	replace YQ_label = "2008Q1" if yrqtr==yq(2008,1)
	replace YQ_label = "2010Q1" if yrqtr==yq(2010,1)
	replace YQ_label = "2012Q1" if yrqtr==yq(2012,1)
	replace YQ_label = "2013Q1" if yrqtr==yq(2013,1)
	replace YQ_label = "2014Q1" if yrqtr==yq(2014,1)

	// relevant time range
	tw (connected log_vu log_h if inrange(yrqtr,yq(2006,3),yq(2012,3)), ///
		mlabel(YQ_label) mlabsize(medlarge)), yti("Log(Vacancies/Unemployment)", si(medlarge)) ///
		scheme(s1color) xti("Log(Hires)", si(medlarge)) ylab(,angle(0) labsi(medlarge)) ///
		xlab(, labsi(medlarge)) name(US_VU_vs_H, replace)
	gr export "${figures}US_VU_vs_H.eps", replace as(eps)
end



*****************************************************************************
**	Figure B.1(a): EU and UE rates Missouri, non-Shimer Adjusted
*****************************************************************************\
cap drop prog do_figb1a
prog define do_figb1a
// read in monthly state Flow data from CPS (seasonally adjusted)
use "${statedata}ue_flows_by_state_cps_sa.dta", clear

// only keep Missouri observations
keep if statenameupper=="MISSOURI"
drop ym	// a bad ym variable
gen ym = ym(year,month)
format ym %tm
tsset ym 	// set as time series

// create quarterly variable
gen quarter = 1 if inrange(month,1,3)
replace quarter = 2 if inrange(month,4,6)
replace quarter = 3 if inrange(month,7,9)
replace quarter = 4 if inrange(month,10,12)

gen yrqtr = yq(year,quarter)
format yrqtr %tq

// only keep observations during relevant time span (2008-2014)
local begmorange = ym(2006,3) 
local endmorange = ym(2013,12)

// create 12 month moving average of UE and EU rates
foreach var in job_separation_rate job_finding_rate {
	gen `var'_12mma = (L11.`var' + L10.`var' + L9.`var' + L8.`var' + L7.`var' + ///
		L6.`var' + L5.`var' + L4.`var' + L3.`var' + L2.`var' + L.`var' + `var')/12
}
	local yti1 "UE/U rate, 12 month moving average"
	local yti2 "EU/E, 12 month moving average"

label var job_finding_rate_12mma "UE/U (left axis)"
label var job_separation_rate_12mma "EU/E (right axis)"

keep if inrange(ym, `begmorange', `endmorange')

qui summ ym
local xmin = `r(min)'
local xmax = `r(max)'
local grend = ym(2013,1)
local policy = ym(2011,4)
// graph EU and UE rates in Missouri
tw (line job_finding_rate_12mma ym, yaxis(1)) (line job_separation_rate_12mma ym, yaxis(2)), ///
	 name(ue_eu_missouri_ctr${center}, replace) graphregion(color(white)) ylab(,angle(0) grid gmax format(%3.2fc)) ///
	 ylab(,angle(0) axis(2) format(%4.3f)) xti("") xmtick(`xmin'(6)`xmax') legend(r(1) symx(*0.6) si(small)) ///
	 yti("`yti1'", si(small) axis(1)) xlab(`xmin'(24)`grend') ///
	 yti("`yti2'", si(small) axis(2)) ///
	 xline(`policy') scheme(s2mono)
gr export "${figures}ue_eu_missouri.eps", replace as(eps)

end

*****************************************************************************
**	Figure B.1(b): s & f rates Missouri, Shimer Adjusted for Time Aggregation Bias
*****************************************************************************
cap drop prog do_figb1b
prog define do_figb1b
// read in monthly state Flow data from CPS (seasonally adjusted)
use "${statedata}f_rate_state_cps_sa_shimeradj.dta", clear

// only keep Missouri observations
keep if statenameupper=="MISSOURI"

// merge on the separation rate data
merge 1:1 ym code month year statename abbv statenameupper fips using ///
	"${statedata}s_rate_state_cps_sa_shimeradj.dta", gen(mizzou)
keep if mizzou == 3
drop mizzou
ren separation_rate job_separation_rate
tsset ym 	// set as time series
// create quarterly variable
gen quarter = 1 if inrange(month,1,3)
replace quarter = 2 if inrange(month,4,6)
replace quarter = 3 if inrange(month,7,9)
replace quarter = 4 if inrange(month,10,12)

gen yrqtr = yq(year,quarter)
format yrqtr %tq

// only keep observations during relevant time span (2008-2014)
local begmorange = ym(2006,3) 
local endmorange = ym(2013,12)

// create 12 month moving average of UE and EU rates
foreach var in job_separation_rate job_finding_rate {
gen `var'_12mma = (L11.`var' + L10.`var' + L9.`var' + L8.`var' + L7.`var' + ///
	L6.`var' + L5.`var' + L4.`var' + L3.`var' + L2.`var' + L.`var' + `var')/12
}

keep if inrange(ym, `begmorange', `endmorange')

local yti1 "Job Finding Rate, 12 month moving average"
local yti2 "Separation Rate, 12 month moving average"

label var job_finding_rate_12mma "Job Finding Rate (left axis)"
label var job_separation_rate_12mma "Separation Rate (right axis)"

qui summ ym
local xmin = `r(min)'
local xmax = `r(max)'
local grend = ym(2013,1)
local policy = ym(2011,4)
// graph EU and UE rates in Missouri
tw (line job_finding_rate_12mma ym, yaxis(1)) (line job_separation_rate_12mma ym, yaxis(2)), ///
	 name(s_f_missouri_ctr${center}, replace) graphregion(color(white)) ///
	ylab(,angle(0) grid gmax format(%3.2fc)) ylab(,angle(0) axis(2) format(%4.3fc)) ///
	xti("") xmtick(`xmin'(6)`xmax') legend(r(1) symx(*0.6) si(small)) ///
	 yti("`yti1'", si(small) axis(1)) xlab(`xmin'(24)`grend') ///
	 yti("`yti2'", si(small) axis(2)) ///
	 xline(`policy') scheme(s2mono)
gr export "${figures}s_f_missouri.eps", replace as(eps)
end 



do_table1
do_table5
do_fig1a_fig3a_figA6
do_figb1a
do_figb1b
constituent_bench


// Functions requiring HWOL data

// histo_decomp_est (does tables 2 and 3, 6 and 7, 9, A.4 and Figures 4, 5 and A.5)
// do_figureA4 (does figure A.4)
// do_table4 (does table 4)
// do_table5 (does table 5)
// do_tablea7 (does table A.7)
// do_tablea8 (does table A.8)
// do_tablea9 (does table A.9)
// fig_dyn_effect_bench (does Figure 2)
// fig_dyn_effect_restrictcomp (does figures A.2 and A.3)
// fig_dyn_wcontrolvars_bench (does figure A.7)
// figure_alt_VU_allvac_bench (does Figure A.8)
// figure_alt_HV_bench (does Figure A.9)
// figure_VU_vs_H (does figure A.10)
